Blame src/internal/slibtool_mkdir_impl.h

3895af
/*******************************************************************/
3895af
/*  slibtool: a skinny libtool implementation, written in C        */
6803d8
/*  Copyright (C) 2016--2018  Z. Gilboa                            */
3895af
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
3895af
/*******************************************************************/
3895af
089c8b
#ifndef SLIBTOOL_MKDIR_IMPL_H
089c8b
#define SLIBTOOL_MKDIR_IMPL_H
089c8b
3895af
#include <errno.h>
3895af
#include <unistd.h>
3895af
267766
#include "slibtool_driver_impl.h"
267766
3895af
#ifndef O_DIRECTORY
3895af
#define O_DIRECTORY 0
3895af
#endif
3895af
267766
static inline int slbt_mkdir(
267766
	const struct slbt_driver_ctx *	dctx,
267766
	const char *			path)
3895af
{
267766
	int fdcwd;
3895af
	int fdlibs;
3895af
267766
	fdcwd = slbt_driver_fdcwd(dctx);
267766
267766
	if ((fdlibs = openat(fdcwd,path,O_DIRECTORY,0)) >= 0)
3895af
		close(fdlibs);
267766
	else if ((errno != ENOENT) || mkdirat(fdcwd,path,0777))
3895af
		if (errno != EEXIST)
3895af
			return -1;
3895af
3895af
	return 0;
3895af
}
089c8b
089c8b
#endif