[hackers] [dmenu] lsx: detect read errors || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Mon, 17 Oct 2011 02:44:23 +0200 (CEST)

changeset: 450:d478c46628d6
branch: lsx
tag: tip
parent: 447:23739cb76476
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Mon Oct 17 01:44:07 2011 +0100
files: lsx.c
description:
lsx: detect read errors


diff -r 23739cb76476 -r d478c46628d6 lsx.c
--- a/lsx.c Sun Oct 16 18:14:51 2011 +0100
+++ b/lsx.c Mon Oct 17 01:44:07 2011 +0100
_AT_@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <dirent.h>
+#include <errno.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
_AT_@ -28,14 +29,15 @@
         struct stat st;
         DIR *dp;
 
- if(!(dp = opendir(dir))) {
+ for(dp = opendir(dir); dp && (d = readdir(dp)); errno = 0)
+ if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < (int)sizeof buf
+ && access(buf, X_OK) == 0 && stat(buf, &st) == 0 && S_ISREG(st.st_mode))
+ puts(d->d_name);
+
+ if(errno != 0) {
                 status = EXIT_FAILURE;
                 perror(dir);
- return;
         }
- while((d = readdir(dp)))
- if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < (int)sizeof buf
- && stat(buf, &st) == 0 && S_ISREG(st.st_mode) && access(buf, X_OK) == 0)
- puts(d->d_name);
- closedir(dp);
+ if(dp)
+ closedir(dp);
 }
Received on Mon Oct 17 2011 - 02:44:23 CEST

This archive was generated by hypermail 2.3.0 : Mon Oct 17 2011 - 02:48:05 CEST