mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-20 01:41:44 +03:00
65e36fc20f
Change the support code for directory creation so that it sets all permission bits (ugo=rwx). The process's currently active umask will be subtracted from these permissions, which leads to the result that (for a standard umask of "022") directories are created with a mode of "0755". So by default, directories created with `prim__createDir` are now also group-executable and other-executable by default. Previous behaviour was to create the directories readable for group and other, but not executable (mode "744"), and thus inaccessible to anyone except the owner.
66 lines
1.2 KiB
C
66 lines
1.2 KiB
C
#include "idris_directory.h"
|
|
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
char* idris2_currentDirectory() {
|
|
char* cwd = malloc(1024); // probably ought to deal with the unlikely event of this being too small
|
|
return getcwd(cwd, 1024); // Freed by RTS
|
|
}
|
|
|
|
int idris2_changeDir(char* dir) {
|
|
return chdir(dir);
|
|
}
|
|
|
|
int idris2_createDir(char* dir) {
|
|
#ifdef _WIN32
|
|
return mkdir(dir);
|
|
#else
|
|
return mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
|
|
#endif
|
|
}
|
|
|
|
typedef struct {
|
|
DIR* dirptr;
|
|
int error;
|
|
} DirInfo;
|
|
|
|
void* idris2_openDir(char* dir) {
|
|
DIR *d = opendir(dir);
|
|
if (d == NULL) {
|
|
return NULL;
|
|
} else {
|
|
DirInfo* di = malloc(sizeof(DirInfo));
|
|
di->dirptr = d;
|
|
di->error = 0;
|
|
|
|
return (void*)di;
|
|
}
|
|
}
|
|
|
|
void idris2_closeDir(void* d) {
|
|
DirInfo* di = (DirInfo*)d;
|
|
|
|
closedir(di->dirptr);
|
|
free(di);
|
|
}
|
|
|
|
int idris2_removeDir(char* path) {
|
|
return rmdir(path);
|
|
}
|
|
|
|
char* idris2_nextDirEntry(void* d) {
|
|
DirInfo* di = (DirInfo*)d;
|
|
struct dirent* de = readdir(di->dirptr);
|
|
|
|
if (de == NULL) {
|
|
di->error = -1;
|
|
return NULL;
|
|
} else {
|
|
return de->d_name;
|
|
}
|
|
}
|