MCPcopy Create free account
hub / github.com/eggert/tz / mkdirs

Function mkdirs

zic.c:4260–4315  ·  view source on GitHub ↗

Ensure that the directories of ARGNAME exist, by making any missing ones. If ANCESTORS, do this only for ARGNAME's ancestors; otherwise, do it for ARGNAME too. Exit with failure if there is trouble. Do not consider an existing file to be trouble. */

Source from the content-addressed store, hash-verified

4258 break;
4259 }
4260 i += clen + 1;
4261 }
4262 if (TZ_MAX_CHARS < nchs + nchs_incr) {
4263 error(N_("too many, or too long, time zone abbreviations"));
4264 exit(EXIT_FAILURE);
4265 }
4266 memmove(&chs[i + nchs_incr], &chs[i], nchs - i);
4267 memcpy(&chs[i], abbr, nchs_incr);
4268 *pnchs = nchs + nchs_incr;
4269 return i;
4270}
4271
4272/* Ensure that the directories of ARGNAME exist, by making any missing
4273 ones. If ANCESTORS, do this only for ARGNAME's ancestors; otherwise,
4274 do it for ARGNAME too. Exit with failure if there is trouble.
4275 Do not consider an existing file to be trouble. */
4276static void
4277mkdirs(char const *argname, bool ancestors)
4278{
4279 /* If -D was specified, do not create directories.
4280 If a file operation's parent directory is missing,
4281 the operation will fail and be diagnosed. */
4282 if (!skip_mkdir) {
4283
4284 char *name = xstrdup(argname);
4285 char *cp = name;
4286
4287 /* On MS-Windows systems, do not worry about drive letters or
4288 backslashes, as this should suffice in practice. Time zone
4289 names do not use drive letters and backslashes. If the -d
4290 option of zic does not name an already-existing directory,
4291 it can use slashes to separate the already-existing
4292 ancestor prefix from the to-be-created subdirectories. */
4293
4294 /* Do not mkdir a root directory, as it must exist. */
4295 while (*cp == '/')
4296 cp++;
4297
4298 while (cp && ((cp = strchr(cp, '/')) || !ancestors)) {
4299 if (cp)
4300 *cp = '\0';
4301 /*
4302 ** Try to create it. It's OK if creation fails because
4303 ** the directory already exists, perhaps because some
4304 ** other process just created it. For simplicity do
4305 ** not check first whether it already exists, as that
4306 ** is checked anyway if the mkdir fails.
4307 */
4308 if (mkdir(name, MKDIR_PERMS) < 0) {
4309 /* Do not report an error if err == EEXIST, because
4310 some other process might have made the directory
4311 in the meantime. Likewise for ENOSYS, because
4312 Solaris 10 mkdir fails with ENOSYS if the
4313 directory is an automounted mount point.
4314 Likewise for EACCES, since mkdir can fail
4315 with EACCES merely because the parent directory
4316 is unwritable. Likewise for most other error
4317 numbers. */

Callers 3

change_directoryFunction · 0.85
open_outfileFunction · 0.85
dolinkFunction · 0.85

Calls 2

xstrdupFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected