Add Linux ptrace() tutorial

This commit is contained in:
Justine Tunney 2022-03-24 08:00:21 -07:00
parent 98909b1391
commit 3b9e66ecba
14 changed files with 1290 additions and 23 deletions

View file

@ -56,21 +56,18 @@ static int openpathname(const char *pathname, int flags, bool *out_noclose) {
* @note microsoft unilaterally deprecated this function lool
*/
FILE *fopen(const char *pathname, const char *mode) {
FILE *f;
FILE *f = 0;
bool noclose;
int fd, flags;
STRACE("fopen(%s)", pathname);
flags = fopenflags(mode);
pathname = fixpathname(pathname, flags);
if ((fd = openpathname(pathname, flags, &noclose)) != -1) {
if ((f = fdopen(fd, mode)) != NULL) {
f->noclose = noclose;
return f;
} else {
if (!noclose) close(fd);
return NULL;
} else if (!noclose) {
close(fd);
}
} else {
return NULL;
}
STRACE("fopen(%#s, %#s) → %p% m", pathname, mode, f);
return f;
}