Skip to content

Commit

Permalink
Add chdir and set errno in fileExists.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed May 9, 2024
1 parent 5b44cc1 commit 5eda9c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/theminst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void install_extra(const char* name, bool* result) {
if (dir.isWritable() == false) {
return fail("%s", dir.string());
}
if (chdir(dir.string())) {
if (dir.chdir()) {
return fail("%s", dir.string());
}

Expand Down
11 changes: 10 additions & 1 deletion src/upath.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ bool upath::isRelative() const {

bool upath::fileExists() {
struct stat sb;
return stat(&sb) == 0 && S_ISREG(sb.st_mode);
if (stat(&sb) == 0) {
if (S_ISREG(sb.st_mode))
return true;
errno = S_ISDIR(sb.st_mode) ? EISDIR : EINVAL;
}
return false;
}

off_t upath::fileSize() {
Expand Down Expand Up @@ -166,6 +171,10 @@ int upath::mkdir(int mode) {
return ::mkdir(string(), mode_t(mode));
}

int upath::chdir() {
return ::chdir(string());
}

int upath::open(int flags, int mode) {
return ::open(string(), flags, mode);
}
Expand Down
1 change: 1 addition & 0 deletions src/upath.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class upath {
bool hasProtocol() const;
int access(int mode = 0);
int mkdir(int mode = 0700);
int chdir();
int open(int flags, int mode = 0666);
FILE* fopen(const char *mode);
int stat(struct stat *st);
Expand Down

0 comments on commit 5eda9c0

Please sign in to comment.