Check for stat errors when getting file attributes on linux
parent
0ae7987cec
commit
d934161447
|
@ -42,11 +42,9 @@ get_full_path(Arena *arena, Path_Search_List *search_list, String_Const_u8 relat
|
||||||
u8 *path_base = relative_base - node_size;
|
u8 *path_base = relative_base - node_size;
|
||||||
block_copy(path_base, node->string.str, node_size);
|
block_copy(path_base, node->string.str, node_size);
|
||||||
String_Const_u8 name = SCu8(path_base, opl);
|
String_Const_u8 name = SCu8(path_base, opl);
|
||||||
printf("get_full_path: trying %.*s\n", string_expand(name));
|
|
||||||
File_Attributes attribs = system_quick_file_attributes(arena, name);
|
File_Attributes attribs = system_quick_file_attributes(arena, name);
|
||||||
if (attribs.size > 0){
|
if (attribs.size > 0){
|
||||||
result = name;
|
result = name;
|
||||||
printf("hit\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,7 +353,7 @@ linux_file_attributes_from_struct_stat(struct stat* file_stat) {
|
||||||
result.size = file_stat->st_size;
|
result.size = file_stat->st_size;
|
||||||
result.last_write_time = linux_ns_from_timespec(file_stat->st_mtim);
|
result.last_write_time = linux_ns_from_timespec(file_stat->st_mtim);
|
||||||
result.flags = linux_convert_file_attribute_flags(file_stat->st_mode);
|
result.flags = linux_convert_file_attribute_flags(file_stat->st_mode);
|
||||||
return result;
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
|
|
@ -132,11 +132,13 @@ system_get_file_list(Arena* arena, String_Const_u8 directory){
|
||||||
(*fip)->file_name = push_u8_stringf(arena, "%.*s", d->d_reclen, name);
|
(*fip)->file_name = push_u8_stringf(arena, "%.*s", d->d_reclen, name);
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if(fstatat(fd, name, &st, 0) == -1){
|
if (fstatat(fd, name, &st, 0) == -1){
|
||||||
perror("fstatat");
|
perror("fstatat");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
(*fip)->attributes = linux_file_attributes_from_struct_stat(&st);
|
||||||
|
}
|
||||||
|
|
||||||
(*fip)->attributes = linux_file_attributes_from_struct_stat(&st);
|
|
||||||
fip = &(*fip)->next;
|
fip = &(*fip)->next;
|
||||||
result.count++;
|
result.count++;
|
||||||
}
|
}
|
||||||
|
@ -163,9 +165,14 @@ system_get_file_list(Arena* arena, String_Const_u8 directory){
|
||||||
internal File_Attributes
|
internal File_Attributes
|
||||||
system_quick_file_attributes(Arena* scratch, String_Const_u8 file_name){
|
system_quick_file_attributes(Arena* scratch, String_Const_u8 file_name){
|
||||||
//LINUX_FN_DEBUG("%.*s", (int)file_name.size, file_name.str);
|
//LINUX_FN_DEBUG("%.*s", (int)file_name.size, file_name.str);
|
||||||
|
Temp_Memory_Block temp(scratch);
|
||||||
|
file_name = push_string_copy(scratch, file_name);
|
||||||
|
File_Attributes result = {};
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
stat((const char*)file_name.str, &file_stat);
|
if (stat((const char*)file_name.str, &file_stat) == 0){
|
||||||
return linux_file_attributes_from_struct_stat(&file_stat);
|
result = linux_file_attributes_from_struct_stat(&file_stat);
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
|
@ -182,9 +189,12 @@ system_load_handle(Arena* scratch, char* file_name, Plat_Handle* out){
|
||||||
internal File_Attributes
|
internal File_Attributes
|
||||||
system_load_attributes(Plat_Handle handle){
|
system_load_attributes(Plat_Handle handle){
|
||||||
LINUX_FN_DEBUG();
|
LINUX_FN_DEBUG();
|
||||||
|
File_Attributes result = {};
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
fstat(*(int*)&handle, &file_stat);
|
if (fstat(*(int*)&handle, &file_stat) == 0){
|
||||||
return linux_file_attributes_from_struct_stat(&file_stat);
|
result = linux_file_attributes_from_struct_stat(&file_stat);
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
|
@ -217,10 +227,11 @@ system_save_file(Arena* scratch, char* file_name, String_Const_u8 data){
|
||||||
int bytes_written = write(fd, data.str, data.size);
|
int bytes_written = write(fd, data.str, data.size);
|
||||||
if (bytes_written == -1) {
|
if (bytes_written == -1) {
|
||||||
perror("write");
|
perror("write");
|
||||||
} else if(bytes_written == data.size) {
|
} else if (bytes_written == data.size) {
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
fstat(fd, &file_stat);
|
if (fstat(fd, &file_stat) == 0){
|
||||||
return linux_file_attributes_from_struct_stat(&file_stat);
|
result = linux_file_attributes_from_struct_stat(&file_stat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
perror("open");
|
perror("open");
|
||||||
|
|
Loading…
Reference in New Issue