mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 06:12:27 +00:00
Implement getcwd() for XNU
This commit is contained in:
parent
417797d218
commit
95173645a1
17 changed files with 239 additions and 77 deletions
|
@ -11,12 +11,31 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "third_party/xed/x86.h"
|
||||
|
||||
/**
|
||||
* @fileoverview x86 instruction length decoder by way of hex pipe.
|
||||
*/
|
||||
|
||||
int fgethex(FILE *f) {
|
||||
int o, t = -1;
|
||||
while (!((o = fgetc(f)) & ~0xFF)) {
|
||||
switch (t) {
|
||||
case -1:
|
||||
t = isxdigit(o) ? hextoint(o) : -1;
|
||||
break;
|
||||
default:
|
||||
if (isxdigit(o)) {
|
||||
return t * 16 + hextoint(o);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t >= 0) return einval();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[argc]) {
|
||||
unsigned c, i, j, l;
|
||||
enum XedError err;
|
||||
|
@ -42,9 +61,8 @@ int main(int argc, char *argv[argc]) {
|
|||
l = xedd.length;
|
||||
if (l <= 0 || l > i) abort();
|
||||
for (j = 0; j < l; ++j) {
|
||||
if (fputhex(buf[j], stdout) == -1) {
|
||||
return errno;
|
||||
}
|
||||
fputc("0123456789ABCDEF"[(buf[j] & 0xf0) >> 4], stdout);
|
||||
fputc("0123456789ABCDEF"[(buf[j] & 0x0f) >> 0], stdout);
|
||||
}
|
||||
putchar('\n');
|
||||
memcpy(&buf[0], &buf[l], i -= l);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue