[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [[PATCH v2 2/2] libxl: replace deprecated readdir_r() with readdir()
On Thu, Jun 2, 2016 at 6:11 AM, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> wrote: > Chris Patterson writes ("[[PATCH v2 2/2] libxl: replace deprecated > readdir_r() with readdir()"): >> - for (;;) { >> + while ((de = readdir(dir)) != NULL) { > ... >> - int r = readdir_r(dir, de_buf, &de); >> - if (r) { >> - LOGE(ERROR, "failed to readdir %s", SYSFS_USB_DEV); >> - break; > > Sadly this is not right because it mishandles errors when reading the > directory, treating them all as EOF. See the error handling info > in the specification for readdir: > http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html > You're right, it should check for the error afterwards. How about something along the lines of: int saved_errno = errno; errno = 0; while ((de = readdir(dir)) != NULL) { ... } if (errno) { LOGE(ERROR, "readdir failed: %s", strerror(errno)); rc = ERROR_FAIL; } errno = saved_errno; ... _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |