@@ -1,4 +1,3 | |||||
1 | // SOPSUYSI_RS232.h |
|
|||
2 |
|
|
1 | #ifndef RS232_H | |
3 | #define RS232_H |
|
2 | #define RS232_H | |
4 |
|
3 |
@@ -58,18 +58,16 rs232portslist_t* rs232getportlist() | |||||
58 | DIR *dir = opendir(path); |
|
58 | DIR *dir = opendir(path); | |
59 | rs232portslist_t* firstitem=NULL; |
|
59 | rs232portslist_t* firstitem=NULL; | |
60 | rs232portslist_t* previtem=NULL; |
|
60 | rs232portslist_t* previtem=NULL; | |
61 |
char linkname |
|
61 | char* linkname; | |
|
62 | char* devName; | |||
62 | int i=0; |
|
63 | int i=0; | |
63 | if(dir!=NULL) |
|
64 | if(dir!=NULL) | |
64 | { |
|
65 | { | |
65 | while ((dp=readdir(dir)) != NULL) |
|
66 | while ((dp=readdir(dir)) != NULL) | |
66 | { |
|
67 | { | |
67 | char* name = (char*)malloc(1024); |
|
68 | int len = strlen(path)+strlen(dp->d_name)+8;//+8 => let's put some margin | |
68 | for(i=0;i<1024;i++) |
|
69 | linkname = (char*)malloc(len); | |
69 | { |
|
70 | memset(linkname,'\0',len); | |
70 | name[i]='\0'; |
|
|||
71 | linkname[i]='\0'; |
|
|||
72 | } |
|
|||
73 | struct stat statbuf; |
|
71 | struct stat statbuf; | |
74 | strcpy(linkname,path); |
|
72 | strcpy(linkname,path); | |
75 | strcat(linkname,"/"); |
|
73 | strcat(linkname,"/"); | |
@@ -77,32 +75,18 rs232portslist_t* rs232getportlist() | |||||
77 | lstat(linkname, &statbuf); |
|
75 | lstat(linkname, &statbuf); | |
78 | if(S_ISLNK(statbuf.st_mode)) |
|
76 | if(S_ISLNK(statbuf.st_mode)) | |
79 | { |
|
77 | { | |
80 |
|
|
78 | devName=realpath(linkname, NULL); | |
|
79 | if(devName!=NULL) | |||
81 | { |
|
80 | { | |
82 | for(i=0;i<1024;i++) |
|
81 | rs232portslist_t* item = (rs232portslist_t*)malloc(sizeof(rs232portslist_t)); | |
83 |
|
|
82 | item->name = devName; | |
84 | linkname[i]='\0'; |
|
83 | item->next = NULL; | |
85 | } |
|
84 | if(NULL!=previtem)previtem->next = item; | |
86 |
|
|
85 | previtem = item; | |
87 | strcat(linkname,"/"); |
|
86 | if(NULL==firstitem)firstitem = item; | |
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 |
|
||||
103 | } |
|
87 | } | |
104 | } |
|
88 | } | |
105 |
|
89 | free(linkname); | ||
106 | } |
|
90 | } | |
107 | } |
|
91 | } | |
108 | return firstitem; |
|
92 | return firstitem; |
General Comments 0
You need to be logged in to leave comments.
Login now