Mercurial > hg > octave-kai > gnulib-hg
annotate lib/mkdir.c @ 5848:a48fb0e98c8c
*** empty log message ***
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 14 May 2005 06:03:57 +0000 |
parents | dc6d827f3011 |
children | 96c32553b4c6 |
rev | line source |
---|---|
3479 | 1 /* On some systems, mkdir ("foo/", 0700) fails because of the trailing |
2 slash. On those systems, this wrapper removes the trailing slash. | |
4665 | 3 |
4 Copyright (C) 2001, 2003 Free Software Foundation, Inc. | |
3479 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software Foundation, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
4665
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
3479 | 19 |
20 /* written by Jim Meyering */ | |
21 | |
22 #include <config.h> | |
23 | |
24 /* Disable the definition of mkdir to rpl_mkdir (from config.h) in this | |
25 file. Otherwise, we'd get conflicting prototypes for rpl_mkdir on | |
26 most systems. */ | |
27 #undef mkdir | |
28 | |
29 #include <sys/types.h> | |
30 #include <sys/stat.h> | |
31 #include <stdio.h> | |
4665 | 32 #include <stdlib.h> |
33 #include <string.h> | |
3479 | 34 |
35 #include "dirname.h" | |
36 #include "xalloc.h" | |
37 | |
38 /* This function is required at least for NetBSD 1.5.2. */ | |
39 | |
40 int | |
41 rpl_mkdir (char const *dir, mode_t mode) | |
42 { | |
43 int ret_val; | |
44 char *tmp_dir; | |
45 size_t len = strlen (dir); | |
46 | |
47 if (len && dir[len - 1] == '/') | |
48 { | |
49 tmp_dir = xstrdup (dir); | |
50 strip_trailing_slashes (tmp_dir); | |
51 } | |
52 else | |
53 { | |
54 tmp_dir = (char *) dir; | |
55 } | |
56 | |
57 ret_val = mkdir (tmp_dir, mode); | |
58 | |
59 if (tmp_dir != dir) | |
60 free (tmp_dir); | |
61 | |
62 return ret_val; | |
63 } |