소스 검색

Improve light folder checking readability

Abdullah ibn Nadjo 7 년 전
부모
커밋
9fda8acac0
1개의 변경된 파일11개의 추가작업 그리고 17개의 파일을 삭제
  1. 11
    17
      src/light.c

+ 11
- 17
src/light.c 파일 보기

@@ -251,25 +251,19 @@ LIGHT_BOOL light_initialize(int argc, char** argv)
251 251
      (mode == LIGHT_SET && light_Configuration.target == LIGHT_MIN_CAP))
252 252
   {
253 253
     /* Make sure we have a valid /etc/light directory, as well as mincap and save */
254
-    mkdirVal = mkdir("/etc/light", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
255
-    if(mkdirVal != 0 && errno != EEXIST)
256
-    {
257
-      LIGHT_ERR("/etc/light does not exist and could not be created, make sure this application is run as root.");
258
-      return FALSE;
259
-    }
254
+    char const * const dirs[3] = {"/etc/light", "/etc/light/mincap", "/etc/light/save"};
255
+    char const * const *dir = dirs;
256
+    char const * const direrr = "'%s' does not exist and could not be created, make sure this application is run as root.";
260 257
 
261
-    mkdirVal = mkdir("/etc/light/mincap", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
262
-    if(mkdirVal != 0 && errno != EEXIST)
258
+    while (dir < dirs + 3)
263 259
     {
264
-      LIGHT_ERR("/etc/light/mincap does not exist and could not be created, make sure this application is run as root.");
265
-      return FALSE;
266
-    }
267
-
268
-    mkdirVal = mkdir("/etc/light/save", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
269
-    if(mkdirVal != 0 && errno != EEXIST)
270
-    {
271
-      LIGHT_ERR("/etc/light/save does not exist and could not be created, make sure this application is run as root.");
272
-      return FALSE;
260
+      mkdirVal = mkdir(*dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
261
+      if(mkdirVal != 0 && errno != EEXIST)
262
+      {
263
+        LIGHT_ERR_FMT(direrr, *dir);
264
+        return FALSE;
265
+      }
266
+      ++dir;
273 267
     }
274 268
   }
275 269