freebsd-dev/gnu/libexec/uucp/libunix/mkdirs.c

58 lines
1.0 KiB
C
Raw Normal View History

1993-08-05 18:28:27 +00:00
/* 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)
{
/* Some versions of uuto will send a double slash. Some
systems will fail to create a directory ending in a
slash. */
if (z[-1] == '/')
continue;
1993-08-05 18:28:27 +00:00
*z = '\0';
1994-05-07 18:14:43 +00:00
if (mkdir (zcopy, imode) != 0
&& errno != EEXIST
&& errno != EISDIR
#ifdef EROFS
&& errno != EROFS
#endif
1994-05-07 18:14:43 +00:00
&& (errno != EACCES || ! fsysdep_directory (zcopy)))
1993-08-05 18:28:27 +00:00
{
1994-05-07 18:14:43 +00:00
ulog (LOG_ERROR, "mkdir (%s): %s", zcopy,
strerror (errno));
ubuffree (zcopy);
return FALSE;
1993-08-05 18:28:27 +00:00
}
*z = '/';
1993-08-05 18:28:27 +00:00
}
}
ubuffree (zcopy);
return TRUE;
}