Mstdlib-1.24.0
File System

Modules

 Common
 
 Permissions
 
 Path
 
 Info
 
 File
 
 Directory
 
 Progress
 
 File System Operations
 

Detailed Description

File sytem routines.

Example (check if a file exists):

if (M_fs_perms_can_access("/file.txt", 0) == M_FS_ERROR_SUCCESS) {
M_printf("path exists\n");
} else {
M_printf("path does not exist\n");
}
ssize_t M_printf(const char *fmt,...)
@ M_FS_ERROR_SUCCESS
Definition: m_fs.h:155
M_fs_error_t M_fs_perms_can_access(const char *path, M_uint32 mode)

Example (information about a file or directory):

M_fs_info_t *info = NULL;
M_printf("user='%s'\n", M_fs_info_get_user(info));
} else {
M_printf("Failed to get file information\n");
}
struct M_fs_info M_fs_info_t
Definition: m_fs.h:127
@ M_FS_PATH_INFO_FLAGS_BASIC
Definition: m_fs.h:237
void M_fs_info_destroy(M_fs_info_t *info) M_FREE(1)
M_fs_error_t M_fs_info(M_fs_info_t **info, const char *path, M_uint32 flags)
const char * M_fs_info_get_user(const M_fs_info_t *info)

Example (normalize path):

const char *p1 = "./abc def/../xyz/./1 2 3/./xyr/.";
const char *n1 = "xyz/1 2 3/xyr";
const char *p2 = "C:\\\\var\\log\\.\\mysql\\\\\\5.1\\..\\..\\mysql.log";
const char *n2 = "C:\\var\\log\\mysql.log";
char *out = NULL;
if (M_str_eq(out, n1)) {
M_printf("p1 normalized correctly\n")
} else {
M_printf("p1 did not normalize correctly\n");
}
} else {
M_printf("failed to normalize p1\n");
}
M_free(out);
if (M_str_eq(out, n2)) {
M_printf("p2 normalized correctly\n")
} else {
M_printf("p2 did not normalize correctly\n");
}
} else {
M_printf("failed to normalize p2\n");
}
M_free(out);
@ M_FS_PATH_NORM_ABSOLUTE
Definition: m_fs.h:215
@ M_FS_PATH_NORM_NONE
Definition: m_fs.h:214
@ M_FS_SYSTEM_WINDOWS
Definition: m_fs.h:369
@ M_FS_SYSTEM_UNIX
Definition: m_fs.h:370
M_fs_error_t M_fs_path_norm(char **out, const char *path, M_uint32 flags, M_fs_system_t sys_type)
void M_free(void *ptr) M_FREE(1)
M_bool M_str_eq(const char *s1, const char *s2)

Example (listing files in a directory):

M_list_str_t *l = NULL;
size_t len;
size_t i;
len = M_list_str_len(l);
for (i=0; i<len; i++) {
M_printf("%s\n", M_list_str_at(l, i));
}
@ M_FS_DIR_WALK_FILTER_READ_INFO_BASIC
Definition: m_fs.h:316
@ M_FS_DIR_WALK_FILTER_FILE
Definition: m_fs.h:291
M_list_str_t * M_fs_dir_walk_strs(const char *path, const char *pat, M_uint32 filter)
const char * M_list_str_at(const M_list_str_t *d, size_t idx)
struct M_list_str M_list_str_t
Definition: m_list_str.h:80
void M_list_str_destroy(M_list_str_t *d) M_FREE(1)
size_t M_list_str_len(const M_list_str_t *d)