OSDN Git Service

branch: yandytex with kpathsea.
[putex/putex.git] / src / texsourc / kpathsea / kpathsea / win32 / dirutil.c
1
2 #include <kpathsea/kpathsea.h>
3
4 #include "dirutil.h"
5
6 /* check a directory */
7 int
8 is_dir (char *buff)
9 {
10   struct stat stats;
11
12   return stat (buff, &stats) == 0 && S_ISDIR (stats.st_mode);
13 }
14
15 /* make a directory */
16 int
17 make_dir (char *buff)
18 {
19   if (_mkdir (buff)) {
20     fprintf(stderr, "mkdir %s error.\n", buff);
21     return (1);
22   }
23   if (_chmod (buff, _S_IREAD | _S_IWRITE)) {
24     fprintf(stderr, "chmod %s failed.\n", buff);
25     return (1);
26   }
27   return (0);
28 }
29
30 int
31 make_dir_p(char *buff)
32 {
33   int  ret = 0;
34   int  i = 0;
35   char *p = buff;
36
37   while (1) {
38     if(*p == '\0') {
39       ret = 0;
40       if(!is_dir(buff)) {
41         if(make_dir(buff)) {
42           ret = 1;
43         }
44       }
45       break;
46     }
47     if(*p == '/' && (i > 0 && *(p-1) != ':')) {
48       *p = '\0';
49       if(!is_dir(buff)) {
50         if(make_dir(buff)) {
51           ret = 1;
52           *p = '/';
53           break;
54         }
55       }
56       *p = '/';
57     }
58     p++;
59     i++;
60   }
61   return ret;
62 }