summaryrefslogtreecommitdiff
path: root/src/internal/slibtool_mkdir_impl.h
blob: ee2c59bb9b27b9f14d63744645c3ccfc41418e68 (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
/*******************************************************************/
/*  slibtool: a skinny libtool implementation, written in C        */
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
/*******************************************************************/

#ifndef SLIBTOOL_MKDIR_IMPL_H
#define SLIBTOOL_MKDIR_IMPL_H

#include <errno.h>
#include <unistd.h>

#include "slibtool_driver_impl.h"

#ifndef O_DIRECTORY
#define O_DIRECTORY 0
#endif

static inline int slbt_mkdir(
	const struct slbt_driver_ctx *	dctx,
	const char *			path)
{
	int fdcwd;
	int fdlibs;

	fdcwd = slbt_driver_fdcwd(dctx);

	if ((fdlibs = openat(fdcwd,path,O_DIRECTORY,0)) >= 0)
		close(fdlibs);
	else if ((errno != ENOENT) || mkdirat(fdcwd,path,0777))
		if (errno != EEXIST)
			return -1;

	return 0;
}

#endif