mirror of
https://github.com/kmod-project/kmod.git
synced 2026-01-27 01:44:26 +00:00
* we use `mkstemp` to create the temporary file since it's a general function in linux system and O_TMPFILE is not supported on all linux system. * add `struct tmpfile` to keep the `dirfd`, temp file `fd` and the filename. Co-developed-by: Wenjie Wang <wenjie2.wang@intel.com> Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com> Co-developed-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Dan He <dan.h.he@intel.com> Signed-off-by: Qingqing Li <qingqing.li@intel.com> Signed-off-by: Yuchi Chen <yuchi.chen@intel.com> Link: https://github.com/kmod-project/kmod/pull/305 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
34 lines
642 B
C
34 lines
642 B
C
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
/*
|
|
* Copyright (C) 2025 Intel Corporation.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdio.h>
|
|
#include <linux/limits.h>
|
|
|
|
#include <shared/macro.h>
|
|
|
|
struct tmpfile {
|
|
char tmpname[PATH_MAX];
|
|
int dirfd;
|
|
int fd;
|
|
};
|
|
|
|
/*
|
|
* Create a temporary file at the directory of `dirfd`
|
|
*/
|
|
_must_check_ _nonnull_(3) FILE *tmpfile_openat(int dirfd, mode_t mode,
|
|
struct tmpfile *file);
|
|
|
|
/*
|
|
* Move the temporary file to `targetname`
|
|
*/
|
|
_nonnull_all_ int tmpfile_publish(struct tmpfile *file, const char *targetname);
|
|
|
|
/*
|
|
* Delete the temporary file
|
|
*/
|
|
_nonnull_all_ void tmpfile_release(struct tmpfile *file);
|