Browse Source

lowl-vcom: sysfs scan: Simplify maybe_strdup into _sysfs_do_read

Luke Dashjr 12 years ago
parent
commit
bfe1a0ba3c
1 changed files with 7 additions and 7 deletions
  1. 7 7
      lowl-vcom.c

+ 7 - 7
lowl-vcom.c

@@ -219,15 +219,16 @@ void _vcom_devinfo_scan_devserial(struct lowlevel_device_info ** const devinfo_l
 
 
 #ifndef WIN32
 #ifndef WIN32
 static
 static
-char *_sysfs_do_read(char *buf, size_t bufsz, const char *devpath, char *devfile, const char *append)
+char *_sysfs_do_read(const char *devpath, char *devfile, const char *append)
 {
 {
+	char buf[0x40];
 	FILE *F;
 	FILE *F;
 	
 	
 	strcpy(devfile, append);
 	strcpy(devfile, append);
 	F = fopen(devpath, "r");
 	F = fopen(devpath, "r");
 	if (F)
 	if (F)
 	{
 	{
-		if (fgets(buf, bufsz, F))
+		if (fgets(buf, sizeof(buf), F))
 		{
 		{
 			size_t L = strlen(buf);
 			size_t L = strlen(buf);
 			while (isCspace(buf[--L]))
 			while (isCspace(buf[--L]))
@@ -240,7 +241,7 @@ char *_sysfs_do_read(char *buf, size_t bufsz, const char *devpath, char *devfile
 	else
 	else
 		buf[0] = '\0';
 		buf[0] = '\0';
 	
 	
-	return buf[0] ? buf : NULL;
+	return buf[0] ? strdup(buf) : NULL;
 }
 }
 
 
 static
 static
@@ -250,7 +251,6 @@ void _sysfs_find_tty(char *devpath, char *devfile, struct lowlevel_device_info *
 	DIR *DT;
 	DIR *DT;
 	struct dirent *de;
 	struct dirent *de;
 	char ttybuf[0x10] = "/dev/";
 	char ttybuf[0x10] = "/dev/";
-	char manuf[0x40], prod[0x40], serial[0x40];
 	char *mydevfile = strdup(devfile);
 	char *mydevfile = strdup(devfile);
 	
 	
 	DT = opendir(devpath);
 	DT = opendir(devpath);
@@ -273,9 +273,9 @@ void _sysfs_find_tty(char *devpath, char *devfile, struct lowlevel_device_info *
 		
 		
 		strcpy(&ttybuf[5], de->d_name);
 		strcpy(&ttybuf[5], de->d_name);
 		devinfo = _vcom_devinfo_findorcreate(devinfo_list, ttybuf);
 		devinfo = _vcom_devinfo_findorcreate(devinfo_list, ttybuf);
-		BFGINIT(devinfo->manufacturer, maybe_strdup(_sysfs_do_read(manuf, sizeof(manuf), devpath, devfile, "/manufacturer")));
-		BFGINIT(devinfo->product, maybe_strdup(_sysfs_do_read(prod, sizeof(prod), devpath, devfile, "/product")));
-		BFGINIT(devinfo->serial, maybe_strdup(_sysfs_do_read(serial, sizeof(serial), devpath, devfile, "/serial")));
+		BFGINIT(devinfo->manufacturer, _sysfs_do_read(devpath, devfile, "/manufacturer"));
+		BFGINIT(devinfo->product, _sysfs_do_read(devpath, devfile, "/product"));
+		BFGINIT(devinfo->serial, _sysfs_do_read(devpath, devfile, "/serial"));
 	}
 	}
 	closedir(DT);
 	closedir(DT);