@@ -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 |
|
|
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 |
|
|
|
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 |
|
|
|
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