-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid varargs conventions when calling open (#126)
* Add an entrypoint for calling open that bypasses the varargs. * Add an entrypoint for calling openat that bypasses the varargs.
- Loading branch information
1 parent
7fcc4f2
commit a94d2d0
Showing
8 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
#include <wasi/libc.h> | ||
|
||
int truncate(const char *path, off_t length) | ||
{ | ||
int fd = open(path, O_WRONLY | O_CLOEXEC | O_NOCTTY); | ||
int fd = __wasilibc_open_nomode(path, O_WRONLY | O_CLOEXEC | O_NOCTTY); | ||
if (fd < 0) | ||
return -1; | ||
|
||
int result = ftruncate(fd, length); | ||
if (result < 0) { | ||
if (result != 0) { | ||
int save_errno = errno; | ||
(void)close(fd); | ||
errno = save_errno; | ||
return -1; | ||
} | ||
|
||
if (close(fd) < 0) | ||
return -1; | ||
|
||
return 0; | ||
return close(fd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters