From c6d1285337dbf064c1d10abf4d7ebfbfc2b4f2e6 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 22 Mar 2013 13:58:43 +0100 Subject: [PATCH] Add pathconf(3). --- libc/Makefile | 1 + libc/include/unistd.h | 24 ++++++++++++++++++++++-- libc/pathconf.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 libc/pathconf.cpp diff --git a/libc/Makefile b/libc/Makefile index ce9b1b33..d0e86596 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -220,6 +220,7 @@ mktemp.o \ on_exit.o \ openat.o \ open.o \ +pathconf.o \ pipe.o \ poll.o \ popen.o \ diff --git a/libc/include/unistd.h b/libc/include/unistd.h index a2f1e13c..7e4e6bd8 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -61,7 +61,27 @@ __BEGIN_DECLS /* TODO: F_* is missing here. */ -/* TODO: _PC_* is missing here. */ +#define _PC_2_SYMLINKS 1 +#define _PC_ALLOC_SIZE_MIN 2 +#define _PC_ASYNC_IO 3 +#define _PC_CHOWN_RESTRICTED 4 +#define _PC_FILESIZEBITS 5 +#define _PC_LINK_MAX 6 +#define _PC_MAX_CANON 7 +#define _PC_MAX_INPUT 8 +#define _PC_NAME_MAX 9 +#define _PC_NO_TRUNC 10 +#define _PC_PATH_MAX 11 +#define _PC_PIPE_BUF 12 +#define _PC_PRIO_IO 13 +#define _PC_REC_INCR_XFER_SIZE 14 +#define _PC_REC_MAX_XFER_SIZE 15 +#define _PC_REC_MIN_XFER_SIZE 16 +#define _PC_REC_XFER_ALIGN 17 +#define _PC_SYMLINK_MAX 18 +#define _PC_SYNC_IO 19 +#define _PC_TIMESTAMP_RESOLUTION 20 +#define _PC_VDISABLE 21 /* TODO: _SC_* is missing here. */ @@ -104,7 +124,6 @@ pid_t getpgrp(void); pid_t getsid(pid_t); int lockf(int, int, off_t); int nice(int); -long pathconf(const char*, int); int pause(void); int setpgid(pid_t, pid_t); int setregid(gid_t, gid_t); @@ -161,6 +180,7 @@ int lchown(const char*, uid_t, gid_t); int link(const char*, const char*); int linkat(int, const char*, int, const char*, int); off_t lseek(int, off_t, int); +long pathconf(const char*, int); int pipe(int [2]); ssize_t pread(int, void*, size_t, off_t); ssize_t pwrite(int, const void*, size_t, off_t); diff --git a/libc/pathconf.cpp b/libc/pathconf.cpp new file mode 100644 index 00000000..06a3d669 --- /dev/null +++ b/libc/pathconf.cpp @@ -0,0 +1,39 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + pathconf.cpp + Get configurable pathname variables. + +*******************************************************************************/ + +#include +#include +#include + +extern "C" long pathconf(const char* path, int name) +{ + switch ( name ) + { + case _PC_PATH_MAX: return -1; // Unbounded + default: + fprintf(stderr, "%s:%u warning: %s(\"%s\", %i) is unsupported\n", + __FILE__, __LINE__, __func__, path, name); + return errno = EINVAL, -1; + } +}