TDengine/include/os/osFile.h

137 lines
4.6 KiB
C
Raw Normal View History

2020-07-31 06:18:23 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program 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.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2021-09-30 08:41:02 +00:00
#ifndef _TD_OS_FILE_H_
#define _TD_OS_FILE_H_
2020-07-31 06:18:23 +00:00
#ifdef __cplusplus
extern "C" {
#endif
#include "osSocket.h"
// If the error is in a third-party library, place this header file under the third-party library header file.
2022-03-21 16:54:21 +00:00
// When you want to use this feature, you should find or add the same function in the following sectio
#ifndef ALLOW_FORBID_FUNC
2022-07-01 06:39:21 +00:00
#define open OPEN_FUNC_TAOS_FORBID
#define fopen FOPEN_FUNC_TAOS_FORBID
#define access ACCESS_FUNC_TAOS_FORBID
#define stat STAT_FUNC_TAOS_FORBID
#define lstat LSTAT_FUNC_TAOS_FORBID
#define fstat FSTAT_FUNC_TAOS_FORBID
#define close CLOSE_FUNC_TAOS_FORBID
#define fclose FCLOSE_FUNC_TAOS_FORBID
#define fsync FSYNC_FUNC_TAOS_FORBID
#define getline GETLINE_FUNC_TAOS_FORBID
// #define fflush FFLUSH_FUNC_TAOS_FORBID
2021-05-08 04:07:18 +00:00
#endif
2021-09-30 08:41:02 +00:00
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
2022-11-02 09:11:12 +00:00
#ifdef WINDOWS
#define TD_PATH_MAX _MAX_PATH
#elif defined(PATH_MAX)
#define TD_PATH_MAX PATH_MAX
#elif defined(_XOPEN_PATH_MAX)
#define TD_PATH_MAX _XOPEN_PATH_MAX
#else
#define TD_PATH_MAX _POSIX_PATH_MAX
#endif
typedef struct TdFile *TdFilePtr;
2022-07-01 06:39:21 +00:00
2023-11-21 08:31:31 +00:00
#define TD_FILE_CREATE 0x0001
#define TD_FILE_WRITE 0x0002
#define TD_FILE_READ 0x0004
#define TD_FILE_TRUNC 0x0008
#define TD_FILE_APPEND 0x0010
#define TD_FILE_TEXT 0x0020
#define TD_FILE_AUTO_DEL 0x0040
#define TD_FILE_EXCL 0x0080
#define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosEOFFile
#define TD_FILE_WRITE_THROUGH 0x0200
#define TD_FILE_CLOEXEC 0x0400
2022-07-01 06:39:21 +00:00
TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions);
2022-08-02 08:13:36 +00:00
TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions);
#define TD_FILE_ACCESS_EXIST_OK 0x1
#define TD_FILE_ACCESS_READ_OK 0x2
#define TD_FILE_ACCESS_WRITE_OK 0x4
2024-06-19 10:54:26 +00:00
#define TD_TMP_FILE_PREFIX "tdengine-"
2022-07-01 06:39:21 +00:00
bool taosCheckAccessFile(const char *pathname, int mode);
int32_t taosLockFile(TdFilePtr pFile);
int32_t taosUnLockFile(TdFilePtr pFile);
2022-07-01 06:39:21 +00:00
int32_t taosUmaskFile(int32_t maskVal);
2022-07-01 06:39:21 +00:00
2023-08-07 07:59:37 +00:00
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *atime);
2022-05-17 05:50:16 +00:00
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno);
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
bool taosCheckExistFile(const char *pathname);
2022-07-01 06:39:21 +00:00
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence);
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t length);
int32_t taosFsyncFile(TdFilePtr pFile);
2022-07-01 06:39:21 +00:00
int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count);
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset);
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset);
void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
2022-07-01 06:39:21 +00:00
int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf);
2022-05-09 09:03:31 +00:00
int64_t taosGetsFile(TdFilePtr pFile, int32_t maxSize, char *__restrict buf);
int32_t taosEOFFile(TdFilePtr pFile);
2022-07-01 06:39:21 +00:00
int32_t taosCloseFile(TdFilePtr *ppFile);
2022-01-19 06:40:28 +00:00
int32_t taosRenameFile(const char *oldName, const char *newName);
int64_t taosCopyFile(const char *from, const char *to);
int32_t taosRemoveFile(const char *path);
2022-07-01 06:39:21 +00:00
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size);
bool taosValidFile(TdFilePtr pFile);
2021-05-08 04:07:18 +00:00
int32_t taosCompressFile(char *srcFileName, char *destFileName);
2023-09-12 06:29:42 +00:00
int32_t taosSetFileHandlesLimit();
2024-01-15 07:46:30 +00:00
int32_t taosLinkFile(char *src, char *dst);
2024-03-12 08:53:56 +00:00
FILE* taosOpenCFile(const char* filename, const char* mode);
int taosSeekCFile(FILE* file, int64_t offset, int whence);
size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream );
size_t taosWriteToCFile(const void* ptr, size_t size, size_t nitems, FILE* stream);
int taosCloseCFile(FILE *);
int taosSetAutoDelFile(char* path);
2024-02-05 08:39:24 +00:00
bool lastErrorIsFileNotExist();
2020-07-31 06:18:23 +00:00
#ifdef __cplusplus
}
#endif
2021-09-30 08:41:02 +00:00
#endif /*_TD_OS_FILE_H_*/