public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: RFC V3 [1/2] test-in-container
Date: Mon, 25 Jun 2018 21:49:00 -0000	[thread overview]
Message-ID: <xna7rik064.fsf@greed.delorie.com> (raw)
In-Reply-To: <df63c348-26ef-5154-d779-8364a6851aa4@redhat.com> (message from Florian Weimer on Mon, 25 Jun 2018 17:00:56 +0200)


Florian Weimer <fweimer@redhat.com> writes:
> On 03/02/2018 12:05 AM, DJ Delorie wrote:
>> Moved mkdir_p() intto xmkdirp.c as xmkdirp(), it takes a mode now too,
>> and a const char *.
>
> The file is missing in the patch.

Sigh, sorry...

/* Error-checking replacement for "mkdir -p".
   Copyright (C) 2018 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <support/support.h>
#include <support/check.h>

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

/* Equivalent of "mkdir -p".  */

int
xmkdirp (const char *path, int mode)
{
  struct stat s;
  const char *slash_p;
  int rv;

  if (path[0] == 0)
    return 0;

  if (stat (path, &s) == 0)
    {
      if (S_ISDIR (s.st_mode))
	return 0;
      errno = EEXIST;
      FAIL_EXIT1 ("mkdir_p (\"%s\", 0%o): %m", path, mode);
    }

  slash_p = strrchr (path, '/');
  if (slash_p)
    {
      while (slash_p > path && slash_p[-1] == '/')
	--slash_p;
      if (slash_p > path)
	{
	  char *parent = xstrndup (path, slash_p - path);
	  rv = xmkdirp (parent, mode);
	  free (parent);
	}
    }

  rv = mkdir (path, mode);
  if (rv != 0)
    FAIL_EXIT1 ("mkdir_p (\"%s\", 0%o): %m", path, mode);

  return 0;
}

  reply	other threads:[~2018-06-25 21:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01 23:05 DJ Delorie
2018-06-25 15:01 ` Florian Weimer
2018-06-25 21:49   ` DJ Delorie [this message]
2018-06-26 11:43     ` Florian Weimer
2018-06-29  1:57       ` RFC V4 test-in-container DJ Delorie
2018-06-29 16:05         ` Joseph Myers
2018-06-29 16:16           ` DJ Delorie
2018-06-29 17:43             ` Joseph Myers
2018-07-06  5:20               ` RFC V5 test-in-container DJ Delorie
2018-07-06 12:36                 ` Carlos O'Donell
2018-06-25 15:17 ` RFC V3 [1/2] test-in-container Florian Weimer
2018-06-25 22:58   ` DJ Delorie
2018-06-25 23:09     ` Florian Weimer
2018-06-26  1:57       ` DJ Delorie
2018-06-26 12:28 ` Florian Weimer
2018-06-26 12:56 ` Florian Weimer
2018-06-26 12:57 ` Florian Weimer
2018-06-28 20:35   ` DJ Delorie
2018-06-26 13:00 ` Florian Weimer
2018-06-26 13:04 ` Florian Weimer
2018-06-28 21:07   ` DJ Delorie
2018-06-29  5:01     ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xna7rik064.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).