免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6950 | 回复: 8
打印 上一主题 下一主题

[其它] ARM9 开发板上 不能locale ,还有怎么查支持的字符集 [复制链接]

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
1 [报告]
发表于 2013-09-23 20:18 |显示全部楼层
本帖最后由 T-Bagwell 于 2013-09-23 20:23 编辑

这个比较好弄
不过没有必要用locale,最好还是用iconv好些

安装locale的话,你需要找到你的arm-linux-的toolchains里面,有对应的locale的库
使用nfs将对应的目录挂到你的板子上,然后localedef安装就可以了

不过最好还是用iconv来做,比locale小很多,而且还方便

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
2 [报告]
发表于 2013-09-23 21:22 |显示全部楼层
iconv -l就可以看的

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
3 [报告]
发表于 2013-09-23 22:02 |显示全部楼层
回复 6# tjf258


    有可能确实是你传递参数的问题了

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
4 [报告]
发表于 2013-09-23 22:08 |显示全部楼层
回复 8# tjf258
  1.      #include <stdio.h>
  2.      #include <errno.h>
  3.      #include <string.h>
  4.      #include <iconv.h>
  5.      #include <stdlib.h>


  6.      /*
  7.       * For state-dependent encodings, changes the state of the conversion
  8.       * descriptor to initial shift state.  Also, outputs the byte sequence
  9.       * to change the state to initial state.
  10.       * This code is assuming the iconv call for initializing the state
  11.       * won't fail due to lack of space in the output buffer.
  12.       */
  13.      #define INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft) \
  14.          { \
  15.              fptr = NULL; \
  16.              ileft = 0; \
  17.              tptr = to; \
  18.              oleft = BUFSIZ; \
  19.              (void) iconv(cd, &fptr, &ileft, &tptr, &oleft); \
  20.              (void) fwrite(to, 1, BUFSIZ - oleft, stdout); \
  21.          }

  22.      int
  23.      main(int argc, char **argv)
  24.      {
  25.          iconv_t cd;
  26.          char    from[BUFSIZ], to[BUFSIZ];
  27.          char    *from_code, *to_code;
  28.          char    *tptr;
  29.          const char  *fptr;
  30.          size_t  ileft, oleft, num, ret;

  31.          if (argc != 3) {
  32.              (void) fprintf(stderr,
  33.                  "Usage: %s from_codeset to_codeset\\n", argv[0]);
  34.              return (1);
  35.          }

  36.          from_code = argv[1];
  37.          to_code = argv[2];

  38.          cd = iconv_open((const char *)to_code, (const char *)from_code);
  39.          if (cd == (iconv_t)-1) {
  40.              /*
  41.               * iconv_open failed
  42.               */
  43.              (void) fprintf(stderr,
  44.                  "iconv_open(%s, %s) failed\\n", to_code, from_code);
  45.              return (1);
  46.          }

  47.          ileft = 0;
  48.          while ((ileft +=
  49.              (num = fread(from + ileft, 1, BUFSIZ - ileft, stdin))) >; 0) {
  50.              if (num == 0) {
  51.                  /*


  52.                   * Input buffer still contains incomplete character
  53.                   * or sequence.  However, no more input character.
  54.                   */

  55.                  /*
  56.                   * Initializes the conversion descriptor and outputs
  57.                   * the sequence to change the state to initial state.
  58.                   */
  59.                  INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft);
  60.                  (void) iconv_close(cd);

  61.                  (void) fprintf(stderr, "Conversion error\\n");
  62.                  return (1);
  63.              }

  64.              fptr = from;
  65.              for (;;) {
  66.                  tptr = to;
  67.                  oleft = BUFSIZ;

  68.                  ret = iconv(cd, &fptr, &ileft, &tptr, &oleft);
  69.                  if (ret != (size_t)-1) {
  70.                      /*
  71.                       * iconv succeeded
  72.                       */

  73.                      /*
  74.                       * Outputs converted characters
  75.                       */
  76.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  77.                      break;
  78.                  }

  79.                  /*
  80.                   * iconv failed
  81.                   */
  82.                  if (errno == EINVAL) {
  83.                      /*
  84.                     * Incomplete character or shift sequence
  85.                       */

  86.                      /*
  87.                       * Outputs converted characters
  88.                       */
  89.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  90.                      /*
  91.                       * Copies remaining characters in input buffer
  92.                       * to the top of the input buffer.
  93.                       */
  94.                      (void) memmove(from, fptr, ileft);
  95.                      /*
  96.                       * Tries to fill input buffer from stdin

  97.                       */
  98.                      break;
  99.                  } else if (errno == E2BIG) {
  100.                      /*
  101.                       * Lack of space in output buffer
  102.                       */

  103.                      /*
  104.                       * Outputs converted characters
  105.                       */
  106.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  107.                      /*
  108.                       * Tries to convert remaining characters in
  109.                       * input buffer with emptied output buffer
  110.                       */
  111.                      continue;
  112.                  } else if (errno == EILSEQ) {
  113.                      /*
  114.                       * Illegal character or shift sequence
  115.                       */

  116.                      /*
  117.                       * Outputs converted characters
  118.                       */
  119.                      (void) fwrite(to, 1, BUFSIZ - oleft, stdout);
  120.                      /*
  121.                       * Initializes the conversion descriptor and
  122.                       * outputs the sequence to change the state to
  123.                       * initial state.
  124.                       */
  125.                      INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft);
  126.                      (void) iconv_close(cd);

  127.                      (void) fprintf(stderr,
  128.                       "Illegal character or sequence\\n");
  129.                      return (1);
  130.                  } else if (errno == EBADF) {
  131.                      /*
  132.                       * Invalid conversion descriptor.
  133.                       * Actually, this shouldn't happen here.
  134.                       */
  135.                      (void) fprintf(stderr, "Conversion error\\n");
  136.                      return (1);
  137.                  } else {
  138.                      /*
  139.                       * This errno is not defined
  140.                       */
  141.                      (void) fprintf(stderr, "iconv error\\n");
  142.                      return (1);
  143.                  }
  144.              }
  145.          }


  146.          /*
  147.           * Initializes the conversion descriptor and outputs
  148.           * the sequence to change the state to initial state.
  149.           */
  150.          INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft);

  151.          (void) iconv_close(cd);
  152.          return (0);
  153.      }
复制代码

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
5 [报告]
发表于 2013-09-24 21:28 |显示全部楼层
方便贴出你的代码不?

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
6 [报告]
发表于 2013-09-25 18:13 |显示全部楼层

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <sys/stat.h>
  6. #include <sys/types.h>
  7. #include <sys/mount.h>
  8. #include <dirent.h>
  9. #include <fcntl.h>
  10. #include <sys/wait.h>
  11. #include <sys/vfs.h>
  12. #include <pthread.h>
  13. #include <netdb.h>
  14. #include <netinet/in.h>
  15. #include <sys/socket.h>
  16. #include <errno.h>
  17. #include <dirent.h>

  18. #include <iconv.h>

  19. //#define TEMP_OUT_SMBCLIENT "./pvrNeighborhood"
  20. #define TEMP_OUT_SMBCLIENT_UTF8 "./pvrNeighborhoodutf8"
  21. #define MAX_FILE_READ_BUFFER_SIZE        512
  22. #define SMB_MAX        20
  23. #define DEFAULT_NETWORK_NEIGHBORHOOD_MOUNTPOINT "/mnt"
  24. #define TEMP_NEIGHBORHOOD_SEARCH_FILE "/mnt/network"
  25. #define TEMP_NMBLOOKUP_FILE         "/mnt/nmblookupfile"

  26. #define MAX_NAME_LEN (256*2)
  27. #define MAX_PER_PAGE        6
  28. static char computerName[256][MAX_NAME_LEN];
  29. static int number;
  30. static         char *host_name[256];
  31. static char pcIpAddress[MAX_NAME_LEN];

  32. static int path_count;
  33. static char path[SMB_MAX][MAX_FILE_READ_BUFFER_SIZE];
  34. //static char utf8path[SMB_MAX][MAX_FILE_READ_BUFFER_SIZE];


  35. int code_convert(char *from_charset,char *to_charset,char *inbuf,int inlen,char *outbuf,int outlen)
  36. {
  37.     iconv_t cd;
  38.     int rc;
  39.     char **pin = &inbuf;
  40.     char **pout = &outbuf;

  41.     cd = iconv_open(to_charset,from_charset);
  42.     if (cd==0)
  43.     {
  44.         return -1;
  45.     }
  46.    
  47.     memset(outbuf,0,outlen);
  48.     if (iconv(cd,pin,&inlen,pout,&outlen)==-1)
  49.     {
  50.         return -1;
  51.     }
  52.    
  53.     iconv_close(cd);
  54.    
  55.     return 0;
  56. }

  57. int u2g(char *inbuf,int inlen,char *outbuf,int outlen)
  58. {
  59.    return code_convert("utf-8","gb2312",inbuf,inlen,outbuf,outlen);
  60. }

  61. int g2u(char *inbuf,size_t inlen,char *outbuf,size_t outlen)
  62. {
  63.     return code_convert("gb2312","utf-8",inbuf,inlen,outbuf,outlen);
  64. }

  65. int smb_attache_mounted(const char *ipaddr, const char *sharename)
  66. {
  67.         char service_path[256];
  68.         char mountpoint[256];
  69.         char stream[MAX_FILE_READ_BUFFER_SIZE];
  70.         FILE *pfile;
  71.         int result = 0;

  72.         if (ipaddr == NULL || sharename == NULL)
  73.             return 0;

  74.         pfile = fopen("/proc/mounts", "r");
  75.         if(!pfile)
  76.                 return 0;

  77.         while (fgets(stream, MAX_FILE_READ_BUFFER_SIZE, pfile))
  78.         {
  79.                 sscanf(stream, "%s %s ", service_path, mountpoint);
  80.                 if (strstr(service_path, ipaddr) != 0 && strstr(service_path, sharename) != 0)
  81.                 {
  82.                         result = 1;
  83.                         fprintf(stderr, "have smb mount\n");
  84.                         break;
  85.                 }
  86.         }

  87.         fclose(pfile);
  88.         return result;
  89. }

  90. /** smb_mount
  91.     * return : 0, mount failed, need password
  92.     *             -1: no shared file or dir
  93.                   >0: shared file or dir's count
  94. */
  95. int smb_mount(const char *ipaddr, const char *username, const char *password, char *ret_path[])
  96. {
  97.         pid_t pid;
  98.         char username_and_passwd[64];
  99.         char stream[MAX_FILE_READ_BUFFER_SIZE];
  100.         char connection_error_message[MAX_FILE_READ_BUFFER_SIZE];
  101.         char srcPath[MAX_FILE_READ_BUFFER_SIZE];
  102.         char data[MAX_FILE_READ_BUFFER_SIZE];
  103.         char diskShareTypeChr[64];
  104.         char shareName[64];
  105.         char *pType;
  106.         DIR *tmp_dir;
  107.         int writefile = 0;
  108.         int status = 0;
  109.         int count = 0;
  110.         FILE *pfile;

  111.         memset(username_and_passwd, 0, 64);
  112.         memset(stream, 0, MAX_FILE_READ_BUFFER_SIZE);
  113.         memset(connection_error_message, 0, MAX_FILE_READ_BUFFER_SIZE);
  114.         memset(path, 0, MAX_FILE_READ_BUFFER_SIZE*SMB_MAX);

  115.         //remove(TEMP_OUT_SMBCLIENT);
  116.         remove(TEMP_OUT_SMBCLIENT_UTF8);

  117.         char smbclientCmd[1024] = { 0 };
  118.         if(username == NULL)
  119.             sprintf(smbclientCmd, "smbclient -L %s -N > %s", ipaddr, TEMP_OUT_SMBCLIENT_UTF8);
  120.         else
  121.             sprintf(smbclientCmd, "smbclient -L %s -U %s%%%s > %s", ipaddr, username, password, TEMP_OUT_SMBCLIENT_UTF8);

  122.        printf("smbclientCmd : %s\n", smbclientCmd);
  123.        system(smbclientCmd);
  124.             

  125.       FILE *utf8file = fopen(TEMP_OUT_SMBCLIENT_UTF8, "r");
  126.       if (utf8file)
  127.       {
  128.          fseek(utf8file, 0, SEEK_END);
  129.          int length = ftell(utf8file);
  130.          if (length > 0)
  131.           {
  132.              fseek(utf8file, 0, SEEK_SET);
  133.              char *bufferUtf8 = (char *)malloc(length + 1);
  134.              memset(bufferUtf8, 0, length + 1);
  135.              fread(bufferUtf8, length, 1, utf8file);
  136.              char *bufferGbk = (char *)malloc(length * 2 + 1);
  137.              u2g(bufferUtf8, length + 1, bufferGbk, length * 2 + 1);
  138.              printf("%s\n\n%s\n\n", bufferUtf8, bufferGbk);
  139.              //FILE *gbkfile = fopen(TEMP_OUT_SMBCLIENT, "w");
  140.              FILE *gbkfile = fopen(TEMP_OUT_SMBCLIENT_UTF8, "w");
  141.              if (gbkfile)
  142.              {
  143.                  fwrite(bufferGbk, strlen(bufferGbk), 1, gbkfile);
  144.                  fclose(gbkfile);
  145.              }
  146.              free(bufferGbk);
  147.              free(bufferUtf8);
  148.           }
  149.           else
  150.           {
  151.              printf("can not open pvrNeighborhood to write\n");
  152.              return -1;
  153.           }
  154.         fclose(utf8file);
  155.       }
  156.       else
  157.       {
  158.          printf("can not open pvrNeighborhoodutf8 to read\n");
  159.          return -1;
  160.       }
  161.        

  162.         //pfile = fopen(TEMP_OUT_SMBCLIENT, "r");
  163.         pfile = fopen(TEMP_OUT_SMBCLIENT_UTF8, "r");
  164.         if(!pfile){
  165.                 printf("open tmpfile error\n");
  166.                 return -1;
  167.         }
  168.         sprintf(connection_error_message, "Connection to %s failed", ipaddr);
  169.         while(count < SMB_MAX && fgets(stream, MAX_FILE_READ_BUFFER_SIZE, pfile)){
  170.                 fprintf(stderr,"smbclient: %s\n",stream);
  171.                 if (NULL != strstr(stream, connection_error_message)){
  172.                         fprintf(stderr, "liuqi????%s\n", connection_error_message);
  173.                         fclose(pfile);                                                                                         
  174.                         return -1;                                                                                          
  175.                 }
  176.                 if (NULL != strstr(stream, "NT_STATUS_ACCESS_DENIED")  
  177.                                 || NULL != strstr(stream, "NT_STATUS_LOGON_FAILURE") ){
  178.                         fclose(pfile);                                                                                         
  179.         fprintf(stderr," NT_STATUS_LOGON_FAILURE smbclient: %s\n",stream);

  180.                         return -1;                                                                                          
  181.                 }
  182.                 if (NULL != strstr(stream, "NT_STATUS_LOGON_FAILURE")){
  183.                         fclose(pfile);
  184.                         return -1;                                                                                          
  185.                 }                                                                                                      

  186.         }
  187.         fclose(pfile);

  188.         //pfile = fopen(TEMP_OUT_SMBCLIENT, "r");
  189.         pfile = fopen(TEMP_OUT_SMBCLIENT_UTF8, "r");
  190.         if(NULL == pfile)
  191.         {
  192.                 //fprintf(stderr, "open %s error\n", TEMP_OUT_SMBCLIENT);
  193.                 fprintf(stderr, "open %s error\n", TEMP_OUT_SMBCLIENT_UTF8);
  194.                 return -1;
  195.         }

  196.         while (fgets(stream, MAX_FILE_READ_BUFFER_SIZE, pfile)){
  197.                 if (0 == strncmp(stream, "\t", strlen("\t"))){
  198.                         memset(path[count], 0 , MAX_FILE_READ_BUFFER_SIZE);
  199.                         memset(diskShareTypeChr, 0, sizeof(diskShareTypeChr));
  200.                         strcpy(diskShareTypeChr, "Disk");
  201.                         strcat(diskShareTypeChr, " ");
  202.                         pType = strstr(stream, diskShareTypeChr);
  203.                         if (NULL == pType){
  204.                                 continue;
  205.                         }
  206.                         strncpy(shareName, stream +1, pType - stream -2);
  207.                         shareName[pType- stream - 2] = '\0';
  208.                         char *pEndOfShareName = shareName + strlen(shareName) -1;
  209.                         while('\40' == *pEndOfShareName)
  210.                                 pEndOfShareName --;
  211.                         *(pEndOfShareName + 1) = '\0';
  212.                         fprintf(stderr, " share name = |%s|\n", shareName);
  213.                         if( '我几年前写的代码,参考一下吧,肯定好用,而且产品化过,现在还在跑着呢 == shareName[strlen(shareName)-1])
  214.                         {
  215.                                 continue;
  216.                         }


  217.                         strcpy(path[count], DEFAULT_NETWORK_NEIGHBORHOOD_MOUNTPOINT);
  218.                         strcat(path[count], "/");
  219.                         strcat(path[count], ipaddr);

  220.                         tmp_dir = opendir(path[count]);
  221.                         if(!tmp_dir)
  222.                                 if (0 != mkdir(path[count], 0777)){
  223.                                         fprintf(stderr, "liuqi<<<<Make %s error\n", path[count]);
  224.                                 }

  225.                         strcat(path[count], "/");
  226.                         strcat(path[count], shareName);
  227.                         fprintf(stderr, "liuqi>>>>%s\n", path[count]);

  228.                         if(smb_attache_mounted(ipaddr, shareName)){
  229.                                char umount_cmd[64] = { 0 };
  230.                                 sprintf(umount_cmd, "umount %s", path[count]);
  231.                                 printf("umount_cmd:%s\n",umount_cmd);
  232.                             system(umount_cmd);
  233.                         }

  234.                        
  235.                        
  236.                         tmp_dir = opendir(path[count]);
  237.                         if(!tmp_dir){
  238.                                 if (0 != mkdir(path[count], 0777)){
  239.                                         fprintf(stderr, "liuqi####Make %s error\n", path[count]);
  240.                                 }
  241.                         }
  242.                         closedir(tmp_dir);
  243.                         sprintf(srcPath, "\\\\%s\\%s", ipaddr, shareName);
  244.                         fprintf(stderr, "liuqi<%s>\n", path[count]);
  245.                         if(username == NULL){
  246.                                 sprintf(data, "user=root,iocharset=cp936");
  247.                                 fprintf(stderr,"liuqi#$%s#%s\n", srcPath, data);
  248.                                 tmp_dir = opendir(path[count]);
  249.                                 fprintf(stderr, "open dir %d\n", tmp_dir);

  250.                                 if (mount(srcPath, path[count], "cifs", 0, data) != 0 )
  251.                                 {
  252.                                         fprintf(stderr, "Mount %s on %s error\n", srcPath, path[count]);

  253.                                         if (errno == EACCES)
  254.                                         {
  255.                                         fprintf(stderr, "Mount Failed %s on %s \n", srcPath, path[count]);

  256.                                 //                rmdir(path[count]);
  257.                                                 fclose(pfile);
  258.                                                 return 0;   //return need password
  259.                                         }
  260.                                         else
  261.                                         {
  262.                                                 fprintf(stderr, "mount error\n");
  263.                                                 ;
  264.                                 //        rmdir(path[count]);
  265.                                         }
  266.                                 }
  267.                                 else{
  268.                                         ret_path[count]=path[count];
  269.                                         fprintf(stderr, "(%s) |(%s)\n", ret_path[count] , path[count]);
  270.                                         count++;
  271.                                 }

  272.                         }
  273.                         else{
  274.                                 sprintf(data, "user=%s,pass=%s,iocharset=cp936",
  275.                                                 username, password);
  276.                                 fprintf(stderr, "|iiiii|%s|\n", data);
  277.                                 if(mount(srcPath, path[count], "cifs", 0, data) != 0 )
  278.                                 {
  279.                                         fprintf(stderr, "Mount Failed %s on %s \n", srcPath, path[count]);
  280.                                         if (errno == EACCES)
  281.                                         {
  282.                                                 fprintf(stderr, stderr, "Mount %s on %s error\n", srcPath, path[count]);
  283.                                 //                rmdir(path[count]);
  284.                                                 fclose(pfile);
  285.                                                 return 0;   //return need password
  286.                                         }
  287.                                         else{
  288.                                                 ;
  289.                                 //        rmdir(path[count]);
  290.                                         }
  291.                                 }
  292.                                 else{
  293.                                         ret_path[count] = path[count];
  294.                                         fprintf(stderr, "(%s) |(%s)\n", ret_path[count] , path[count]);
  295.                                         count++;
  296.                                 }

  297.                         }
  298.                 }
  299.         }
  300.         fclose(pfile);
  301.         path_count = count;
  302.         fprintf(stderr, "#%s#\n", path[count]);
  303.         return count == 0 ? 0 : -1;  //if count == 0, return no shared file
  304. }
  305. extern int covert(char *desc, char *src, char *input, size_t ilen, char *output, size_t olen);

  306. int smb_get_path_count(int* a_count)
  307. {
  308.         * a_count =  path_count;
  309.         return 0;
  310. }
  311. int smb_mount_path_get(int i,char *string_path)
  312. {
  313.         char tmpStr[128];

  314.         memset(tmpStr, 0, sizeof(char)*128);
  315.         memcpy(tmpStr, path[i], strlen(path[i]));
  316.         covert("utf-8", "gb18030", tmpStr, strlen(tmpStr), string_path, sizeof(char)*MAX_FILE_READ_BUFFER_SIZE-1);
  317.         //string_path = utf8path[i];
  318.         fprintf(stderr, "#%s#\n", path[i]);
  319.         fprintf(stderr, "========%s=======\n", string_path);
  320.         return 0;
  321. }

  322. int get_smb_tree_host(int num, char *host_name_init[])
  323. {
  324.         int i = num * MAX_PER_PAGE;
  325.         int count = 0;
  326. fprintf(stderr, "number = %d, host_name_init[count] = %s\n", number, host_name[i]);

  327.         for( count =0 ; i < number && count < 6; i++)
  328.         {
  329.                 fprintf(stderr, "host_name_init[count] = %s\n", host_name[i]);
  330.                 host_name_init[count] = host_name[i];
  331.                 count++;
  332.         }
  333. fprintf(stderr, " liuqi >>>> count = %d\n", count);
  334.         return count;
  335. }


  336. int smb_tree_init()
  337. {
  338.         char tempFilename[] = TEMP_NEIGHBORHOOD_SEARCH_FILE;
  339.         char sharedName[MAX_NAME_LEN];
  340.         char path[MAX_NAME_LEN];
  341.         int i = 0;
  342.         memset(computerName, 0 , 256*MAX_NAME_LEN);
  343.         memset(sharedName, 0, MAX_NAME_LEN);

  344.         pid_t pid= fork();

  345.         if (pid == 0)
  346.         {
  347.                 int writeFile= open(tempFilename, O_CREAT | O_RDWR | O_TRUNC,
  348.                         S_IREAD | S_IWRITE);

  349.                 close(1);
  350.                 dup2(writeFile, 1);

  351.                 execlp("smbtree", "smbtree", "-S" , "-N","-s", "/home/work/samba/lib/smb.conf", NULL);
  352.                 perror("smbtree");
  353.                 return 0;
  354.         }
  355.         else if (pid >0)
  356.         {
  357.                 int status;
  358.                 while (1){
  359.                         pid_t ptw = waitpid(pid, NULL, WNOHANG);
  360.                         if (ptw == pid)
  361.                                 break;
  362.                         usleep(500000);     
  363.                 }

  364.                 FILE *pfile;
  365.                 pfile = fopen(tempFilename, "r");
  366.                 char stream[MAX_NAME_LEN];
  367.                 if(!pfile){
  368.                         fprintf(stderr, "Can't mount network directory!\n");
  369.                         return;
  370.                 }
  371.                 while (fgets(stream, MAX_NAME_LEN, pfile)){
  372.                         char *c;
  373.                         if(strstr(stream, "smbtree: not found"))
  374.                         {
  375.                                 return 0;
  376.                         }
  377.                         if( !strncmp(stream, "\t\\\\", strlen("\t\\\\"))){
  378.                                 sscanf(stream, "\t%[^\40\t]", path);
  379.                                 c = strrchr(path, '\\');
  380.                                 if(NULL == c)
  381.                                         continue;
  382.                                 c++;
  383.                                 memset(computerName[i], 0, MAX_NAME_LEN);
  384.                                 strcpy(computerName[i], c);
  385.                                 host_name[i] = computerName[i];
  386.                                 fprintf(stderr, "liuqi>>|%s|\n", computerName[i]);
  387.                                 i++;
  388.                                 continue;
  389.                         }
  390.                 }
  391.                 fclose(pfile);
  392.         }
  393.         fprintf(stderr, "i = %d\n", i);
  394.         number = i;
  395.         return i;

  396. }

  397. char *get_host_ipaddr(char *name)
  398. {
  399.         int writeFile;
  400.         memset(pcIpAddress, 0, MAX_NAME_LEN);
  401.         pid_t pid= fork();
  402.         if (pid == 0)
  403.         {
  404.                 writeFile = open(TEMP_NMBLOOKUP_FILE, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
  405.                 close(1);
  406.                 dup2(writeFile, 1);
  407.                 execlp("nmblookup", "nmblookup", name, NULL);
  408.                 return NULL;
  409.         }
  410.         else if (pid >0){
  411.                 while(1){
  412.                         pid_t ptw = waitpid(pid, NULL, WNOHANG);
  413.                         if (ptw == pid)
  414.                                 break;
  415.                         usleep(50000);
  416.                 }
  417.                 FILE *pfile;
  418.                 pfile = fopen(TEMP_NMBLOOKUP_FILE, "r");
  419.                 char stream[MAX_NAME_LEN];
  420.                 if(!pfile){
  421.                         fprintf(stderr, "Can't mount network directory!\n");
  422.                         return NULL;
  423.                 }

  424.                 while (fgets(stream, MAX_NAME_LEN, pfile)){
  425.                         char *c;
  426.                         char temp[MAX_NAME_LEN];

  427.                         sscanf(stream, "%s %s", pcIpAddress, temp);

  428.                         c = strchr(pcIpAddress, '.');
  429.                         if(NULL == c)
  430.                                 continue;
  431.                         c++;

  432.                         c = strchr(pcIpAddress, '.');
  433.                         if(NULL == c)
  434.                                 continue;
  435.                         c++;

  436.                         c = strchr(pcIpAddress, '.');
  437.                         if(NULL == c)
  438.                                 continue;       
  439.                         if(pcIpAddress[0]>'0'&&pcIpAddress[0]<'9')
  440.                         return pcIpAddress;
  441.                 }
  442.                 fclose(pfile);

  443.         }
  444.         return pcIpAddress;

  445. }

  446. smb_umount()
  447. {
  448.     int i = 0;
  449.     for(i =0; i < path_count; i++){
  450.             char umount_cmd[1024] = { 0 };
  451.             fprintf(umount_cmd, "umount %s", path[i]);
  452.             system(umount_cmd);
  453.         }
  454.         path_count = 0;
  455. }


  456. #if 0
  457. int main(int argc, char *argv[])
  458. {
  459.         int ret=0;
  460.         char *str[10];
  461.         if(argc == 4)
  462.                 ret = smb_mount(argv[1], argv[2], argv[3], str);
  463.         else
  464.                 ret = smb_mount(argv[1], NULL, NULL, str);

  465.         int i=0;
  466.         for(i=0; i < ret; i++)
  467.         fprintf(stderr, "!%s!\n", str[i]);

  468.         return 0;
  469. }
  470. #endif

复制代码
我几年前写的代码,参考一下吧,肯定好用,而且产品化过,现在还在跑着呢

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
7 [报告]
发表于 2013-09-26 11:10 |显示全部楼层
本帖最后由 T-Bagwell 于 2013-09-26 11:10 编辑
tjf258 发表于 2013-09-25 22:14
谢谢!!

宿主机上能正常iconv了


如果是编译iconv的话,我觉得你可以先试试编译成静态库,.a
奈何我没有板子了,都给人了……

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
8 [报告]
发表于 2013-09-27 17:24 |显示全部楼层
这就是传说中的移植了
交叉编译iconv,编译iconv的.a

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
9 [报告]
发表于 2013-12-12 07:11 |显示全部楼层
回复 18# zhangpipi123


    没用的,他没有locale的支持,一般嵌入式里面就是C和english我记得
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP