summaryrefslogtreecommitdiffstats
path: root/gnu/libexec/uucp/libunix/mkdirs.c
blob: a4e0b67bb8c3946f34a6ffc542fbf8c76fbf59b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* mkdirs.c
   Create any directories needed for a file name.  */

#include "uucp.h"

#include "uudefs.h"
#include "sysdep.h"
#include "system.h"

#include <errno.h>

boolean
fsysdep_make_dirs (zfile, fpublic)
     const char *zfile;
     boolean fpublic;
{
  char *zcopy, *z;
  int imode;

  zcopy = zbufcpy (zfile);

  if (fpublic)
    imode = IPUBLIC_DIRECTORY_MODE;
  else
    imode = IDIRECTORY_MODE;

  for (z = zcopy; *z != '\0'; z++)
    {
      if (*z == '/' && z != zcopy)
	{
	  *z = '\0';
	  if (! fsysdep_directory (zcopy))
	    {
	      if (mkdir (zcopy, imode) != 0)
		{
		  ulog (LOG_ERROR, "mkdir (%s): %s", zcopy,
			strerror (errno));
		  ubuffree (zcopy);
		  return FALSE;
		}
	    }
	  *z = '/';
	}
    }

  ubuffree (zcopy);

  return TRUE;
}
OpenPOWER on IntegriCloud