]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
Fix getcwd: return char* (POSIX) instead of int
authorTulio A M Mendes <[email protected]>
Sun, 19 Apr 2026 17:38:54 +0000 (14:38 -0300)
committerTulio A M Mendes <[email protected]>
Sun, 19 Apr 2026 17:38:54 +0000 (14:38 -0300)
commitf4944a2d6d73af36ebacb0c057f2d842d66e8e8e
tree3f0bf6e5ed6ea8ffa82302b782e99887c66c3fbe
parent267ba8074e567232bfff3f748dd7abda5407a8c9
Fix getcwd: return char* (POSIX) instead of int

ulibc getcwd() returned int (0 on success, -1 on error) but POSIX
specifies char* (buf on success, NULL on error). Bash and other
ported software call getcwd expecting a pointer return; getting 0
(NULL) on success caused:

  shell-init: error retrieving current directory: getcwd:
  cannot access parent directories: Bad address

The kernel syscall already returns 0 on success, so the fix is in
the ulibc wrapper: return buf on success, NULL on error (setting
errno). This matches the newlib wrapper in posix_stubs.c which had
the correct signature all along.

Updated all internal callers (sh, pwd, realpath) from int-style
checks (>= 0 / < 0) to pointer-style checks (truthy / !ptr).
user/cmds/pwd/pwd.c
user/cmds/sh/sh.c
user/ulibc/include/unistd.h
user/ulibc/src/stdlib.c
user/ulibc/src/unistd.c