/[global]/global/libutil/test.c
ViewVC logotype

Diff of /global/libutil/test.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by shigio, Sun Nov 28 01:04:58 2004 UTC revision 1.6 by shigio, Sun Apr 3 10:54:51 2005 UTC
# Line 37  Line 37 
37  #include "test.h"  #include "test.h"
38    
39  /*  /*
40     * Decide whether or not the path is binary file.
41     *
42     *      i)      path
43     *      r)      0: is not binary, 1: is binary
44     */
45    static int
46    is_binary(path)
47            char *path;
48    {
49            int ip;
50            char buf[32];
51            int i, c, size;
52    
53            ip = open(path, 0);
54            if (ip < 0)
55                    die("cannot open file '%s' in read mode.", path);
56            size = read(ip, buf, sizeof(buf));
57            close(ip);
58            if (size < 0)
59                    return 1;
60            if (!strncmp(buf, "!<arch>", 7))
61                    return 1;
62            for (i = 0; i < size; i++) {
63                    c = (unsigned char)buf[i];
64                    if (c == 0 || c > 127)
65                            return 1;
66            }
67            return 0;
68    }
69    /*
70   * test:   * test:
71   *   *
72   *      i)      flags   file flags   *      i)      flags   file flags
# Line 47  Line 77 
77   *                      "s"     [ -s path ]   *                      "s"     [ -s path ]
78   *                      "w"     [ -w path ]   *                      "w"     [ -w path ]
79   *                      "x"     [ -x path ]   *                      "x"     [ -x path ]
80     *                      "b"     [ -b path ]
81   *   *
82   *      i)      path    path   *      i)      path    path
83   *                      if NULL then previous path.   *                      if NULL then previous path.
84   *      r)              0: no, 1: ok   *      r)              0: no, 1: ok
85   *   *
86   * You can specify more than one character. It assumed 'and' test.   * You can specify more than one character. It assumed 'AND' test.
87   */   */
88  int  int
89  test(flags, path)  test(flags, path)
# Line 67  test(flags, path) Line 98  test(flags, path)
98                          return 0;                          return 0;
99          while ((c = *flags++) != 0) {          while ((c = *flags++) != 0) {
100                  switch (c) {                  switch (c) {
101                    case 'b':
102                            if (!is_binary(path))
103                                    return 0;
104                            break;
105                  case 'f':                  case 'f':
106                          if (!S_ISREG(sb.st_mode))                          if (!S_ISREG(sb.st_mode))
107                                  return 0;                                  return 0;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26