##// END OF EJS Templates
Removed ugly bug in serial port enumeration on linux.
Jeandet Alexis -
r45:def3deb8bd34 qt
parent child
Show More
@@ -1,4 +1,3
1 // SOPSUYSI_RS232.h
2 1 #ifndef RS232_H
3 2 #define RS232_H
4 3
@@ -58,18 +58,16 rs232portslist_t* rs232getportlist()
58 58 DIR *dir = opendir(path);
59 59 rs232portslist_t* firstitem=NULL;
60 60 rs232portslist_t* previtem=NULL;
61 char linkname[1024];
61 char* linkname;
62 char* devName;
62 63 int i=0;
63 64 if(dir!=NULL)
64 65 {
65 66 while ((dp=readdir(dir)) != NULL)
66 67 {
67 char* name = (char*)malloc(1024);
68 for(i=0;i<1024;i++)
69 {
70 name[i]='\0';
71 linkname[i]='\0';
72 }
68 int len = strlen(path)+strlen(dp->d_name)+8;//+8 => let's put some margin
69 linkname = (char*)malloc(len);
70 memset(linkname,'\0',len);
73 71 struct stat statbuf;
74 72 strcpy(linkname,path);
75 73 strcat(linkname,"/");
@@ -77,32 +75,18 rs232portslist_t* rs232getportlist()
77 75 lstat(linkname, &statbuf);
78 76 if(S_ISLNK(statbuf.st_mode))
79 77 {
80 if(-1!=readlink(linkname,name,1024))
78 devName=realpath(linkname, NULL);
79 if(devName!=NULL)
81 80 {
82 for(i=0;i<1024;i++)
83 {
84 linkname[i]='\0';
85 }
86 strcpy(linkname,path);
87 strcat(linkname,"/");
88 strcat(linkname,name);
89 for(i=0;i<1024;i++)
90 {
91 name[i]='\0';
92 }
93 if(NULL!=realpath(linkname, name))
94 {
95 rs232portslist_t* item = (rs232portslist_t*)malloc(sizeof(rs232portslist_t));
96 item->name = name;
97 item->next = NULL;
98 if(NULL!=previtem)previtem->next = item;
99 previtem = item;
100 if(NULL==firstitem)firstitem = item;
101 }
102
81 rs232portslist_t* item = (rs232portslist_t*)malloc(sizeof(rs232portslist_t));
82 item->name = devName;
83 item->next = NULL;
84 if(NULL!=previtem)previtem->next = item;
85 previtem = item;
86 if(NULL==firstitem)firstitem = item;
103 87 }
104 88 }
105
89 free(linkname);
106 90 }
107 91 }
108 92 return firstitem;
General Comments 0
You need to be logged in to leave comments. Login now