/[LeafOK_CVS]/lbbs/src/io.c
ViewVC logotype

Diff of /lbbs/src/io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.52 by sysadm, Thu Oct 16 12:11:31 2025 UTC Revision 1.54 by sysadm, Sat Oct 18 01:50:48 2025 UTC
# Line 859  void igetch_reset() Line 859  void igetch_reset()
859          int ch;          int ch;
860          do          do
861          {          {
862                  ch = igetch(0);                  ch = igetch(100);
863          } while (ch != KEY_NULL && ch != KEY_TIMEOUT);          } while (ch != KEY_NULL && ch != KEY_TIMEOUT);
864  }  }
865    
866    int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char *p_conv, size_t conv_size, int *p_conv_len)
867    {
868            char *in_buf;
869            char *out_buf;
870            size_t in_bytes;
871            size_t out_bytes;
872            int ret;
873    
874            in_buf = p_buf + *p_buf_offset;
875            in_bytes = (size_t)(*p_buf_len - *p_buf_offset);
876            out_buf = p_conv + *p_conv_len;
877            out_bytes = conv_size - (size_t)(*p_conv_len);
878    
879            while (in_bytes > 0)
880            {
881                    ret = (int)iconv(cd, &in_buf, &in_bytes, &out_buf, &out_bytes);
882                    if (ret == -1)
883                    {
884                            if (errno == EINVAL) // Incomplete
885                            {
886    #ifdef _DEBUG
887                                    log_error("iconv(inbytes=%d, outbytes=%d) error: EINVAL\n", in_bytes, out_bytes);
888    #endif
889                                    *p_buf_len = (int)(p_buf + *p_buf_len - in_buf);
890                                    *p_buf_offset = 0;
891                                    *p_conv_len = (int)(conv_size - out_bytes);
892                                    memmove(p_buf, in_buf, (size_t)(*p_buf_len));
893    
894                                    break;
895                            }
896                            else if (errno == E2BIG)
897                            {
898                                    log_error("iconv(inbytes=%d, outbytes=%d) error: E2BIG\n", in_bytes, out_bytes);
899                                    return -1;
900                            }
901                            else if (errno == EILSEQ)
902                            {
903                                    if (in_bytes > out_bytes || out_bytes <= 0)
904                                    {
905                                            log_error("iconv(inbytes=%d, outbytes=%d) error: EILSEQ and E2BIG\n", in_bytes, out_bytes);
906                                            return -2;
907                                    }
908    
909                                    *out_buf = *in_buf;
910                                    in_buf++;
911                                    out_buf++;
912                                    in_bytes--;
913                                    out_bytes--;
914    
915                                    continue;
916                            }
917                    }
918                    else
919                    {
920                            *p_buf_len = 0;
921                            *p_buf_offset = 0;
922                            *p_conv_len = (int)(conv_size - out_bytes);
923    
924                            break;
925                    }
926            }
927    
928            return 0;
929    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1