--- /dev/null
+void __procfdname(char *buf, unsigned fd)
+{
+ unsigned i, j;
+ for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++);
+ if (!fd) {
+ buf[i] = '0';
+ buf[i+1] = 0;
+ return;
+ }
+ for (j=fd; j; j/=10, i++);
+ buf[i] = 0;
+ for (; fd; fd/=10) buf[--i] = '0' + fd%10;
+}
#include <errno.h>
#include <unistd.h>
+void __procfdname(char *, unsigned);
+
char *realpath(const char *restrict filename, char *restrict resolved)
{
int fd;
fd = open(filename, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
if (fd < 0) return 0;
- snprintf(buf, sizeof buf, "/proc/self/fd/%d", fd);
+ __procfdname(buf, fd);
if (!resolved) {
alloc = 1;
#include <stdio.h>
#include <errno.h>
+void __procfdname(char *, unsigned);
+
int fexecve(int fd, char *const argv[], char *const envp[])
{
- static const char proc[] = "/proc/self/fd/%d";
- char buf[sizeof proc + 3*sizeof(int)];
- snprintf(buf, sizeof buf, proc, fd);
+ char buf[15 + 3*sizeof(int)];
+ __procfdname(buf, fd);
execve(buf, argv, envp);
if (errno == ENOENT) errno = EBADF;
return -1;
#include <stdio.h>
#include "syscall.h"
+void __procfdname(char *, unsigned);
+
int fchmodat(int fd, const char *path, mode_t mode, int flag)
{
if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag);
return __syscall_ret(fd2);
}
- snprintf(proc, sizeof proc, "/proc/self/fd/%d", fd2);
+ __procfdname(proc, fd2);
if (!(ret = __syscall(SYS_stat, proc, &st)) && !S_ISLNK(st.st_mode))
ret = __syscall(SYS_chmod, proc, mode);
#include <stdio.h>
#include <string.h>
+void __procfdname(char *, unsigned);
+
int ttyname_r(int fd, char *name, size_t size)
{
char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2];
if (!isatty(fd)) return ENOTTY;
- snprintf(procname, sizeof procname, "/proc/self/fd/%d", fd);
+ __procfdname(procname, fd);
l = readlink(procname, name, size);
if (l < 0) return errno;