Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fvbe.git;a=commitdiff;h=3d624225ea398450eb5d1a413b7bfb02d29562ad
commit 3d624225ea398450eb5d1a413b7bfb02d29562ad Author: James Buren <[email protected]> Date: Sun Aug 25 18:35:15 2013 -0500 block: replace usage of readlink with readlink0 diff --git a/src/block.c b/src/block.c index 217c0b4..e46ff2e 100644 --- a/src/block.c +++ b/src/block.c @@ -1359,26 +1359,16 @@ extern struct raid *raid_open(struct device *device) for( int i = 0 ; i < disks ; ++i ) { - ssize_t n = -1; - strfcpy(path,sizeof(path),"/sys/class/block/%s/md/rd%d",basename(base),i); - // < 1 means empty or error. == sizeof(buf) means it is truncated. - if((n = readlink(path,buf,sizeof(buf))) < 1 || n == sizeof(buf)) + if(!readlink0(path,buf,sizeof(buf))) { - if(n != -1) - errno = ERANGE; - - error(strerror(errno)); - for( int j = 0 ; j < i ; ++j ) device_close(devices[j]); return 0; } - buf[n] = 0; - if(strncmp(buf,"dev-",4) != 0) { error("invalid raid slave name"); diff --git a/src/utility.c b/src/utility.c index d3582f2..05b2742 100644 --- a/src/utility.c +++ b/src/utility.c @@ -69,12 +69,17 @@ extern bool readlink0(const char *path,char *buf,size_t size) n = readlink(path,buf,size); - if(n > 0 && n < size) + if(n > 0 && (size_t) n < size) { buf[n] = 0; return true; } + if(n > 0) + errno = ERANGE; + + error(strerror(errno)); + return false; } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
