util: add/use new os_mkdir() function

os_mkdir() is a simple wrapper around mkdir() or _mkdir().

Remove a bunch of unneeded #includes in dd_util.h.  Testing by
compiling llvmpipe and radeonsi (the only user of the dd_util.h
header).

There's a few other mkdir() callsites that I haven't touched but
could be updated to os_mkdir().

Signed-off-by: Brian Paul <brian.paul@broadcom.com>
Tested-by: Mauro Rossi <issor.oruam@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35841>
This commit is contained in:
Brian Paul 2025-06-30 12:35:36 -06:00 committed by Marge Bot
parent b85265bbc2
commit 6fe6c18c12
5 changed files with 27 additions and 19 deletions

View file

@ -27,6 +27,7 @@
#include "dd_pipe.h"
#include "util/os_file.h"
#include "util/u_dump.h"
#include "util/format/u_format.h"
#include "util/u_framebuffer.h"
@ -54,7 +55,7 @@ dd_get_debug_filename_and_mkdir(char *buf, size_t buflen, bool verbose)
snprintf(dir, sizeof(dir), "%s/"DD_DIR, debug_get_option("HOME", "."));
if (mkdir(dir, 0774) && errno != EEXIST)
if (os_mkdir(dir, 0774) && errno != EEXIST)
fprintf(stderr, "dd: can't create a directory (%i)\n", errno);
snprintf(buf, buflen, "%s/%s_%u_%08u", dir, proc_name, (unsigned int)getpid(),

View file

@ -29,22 +29,6 @@
#define DD_UTIL_H
#include <stdio.h>
#include <errno.h>
#include "c99_alloca.h"
#include "util/u_atomic.h"
#include "util/u_debug.h"
#include "util/u_string.h"
#include "util/detect.h"
#if DETECT_OS_POSIX
#include <unistd.h>
#include <sys/stat.h>
#elif DETECT_OS_WINDOWS
#include <direct.h>
#include <process.h>
#define mkdir(dir, mode) _mkdir(dir)
#endif
struct pipe_screen;

View file

@ -46,8 +46,8 @@
#include "util/detect_os.h"
#include "util/u_math.h"
#include "util/u_debug.h"
#include "util/os_file.h"
#include "driver_ddebug/dd_util.h"
#include "lp_bld_debug.h"
#include "lp_bld_intr.h"
@ -377,7 +377,7 @@ lp_function_add_debug_info(gallivm_state *gallivm, LLVMValueRef func, LLVMTypeRe
if (!gallivm->file) {
uint32_t shader_index = p_atomic_add_return(&global_shader_index, 1);
mkdir(LP_NIR_SHADER_DUMP_DIR, 0755);
os_mkdir(LP_NIR_SHADER_DUMP_DIR, 0755);
asprintf(&gallivm->file_name, "%s/%u.nir", LP_NIR_SHADER_DUMP_DIR, shader_index);

View file

@ -5,6 +5,7 @@
#include "os_file.h"
#include "detect_os.h"
#include "util/detect.h"
#include <errno.h>
#include <fcntl.h>
@ -12,6 +13,7 @@
#include <sys/stat.h>
#if DETECT_OS_WINDOWS
#include <direct.h>
#include <io.h>
#define open _open
#define fdopen _fdopen
@ -21,6 +23,7 @@
#define O_CREAT _O_CREAT
#define O_EXCL _O_EXCL
#define O_WRONLY _O_WRONLY
#define mkdir(dir, mode) _mkdir(dir)
#else
#include <unistd.h>
#ifndef F_DUPFD_CLOEXEC
@ -268,3 +271,14 @@ os_same_file_description(int fd1, int fd2)
return -1;
#endif
}
int
os_mkdir(const char *pathname, int mode)
{
#if DETECT_OS_WINDOWS
return _mkdir(pathname);
#else
return mkdir(pathname, mode);
#endif
}

View file

@ -52,6 +52,15 @@ os_read_file(const char *filename, size_t *size);
int
os_same_file_description(int fd1, int fd2);
/*
* Make a directory. The file permissions bitmask 'mode' may be ignored
* (such as on Windows).
* Return 0 for success, -1 on failure (setting errno).
*/
int
os_mkdir(const char *pathname, int mode);
#ifdef __cplusplus
}
#endif