about summary refs log tree commit diff
path: root/sysdeps/posix
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2012-08-17 13:52:32 -0700
committerRoland McGrath <roland@hack.frob.com>2012-08-17 13:52:32 -0700
commit7c6f9d53c1f57bb9b679fcdb39d2b5a9c63e46d3 (patch)
treea74652f06f7bc02a2bb11ce3dc7adbdfe756fbee /sysdeps/posix
parent3bd9e9931bcb4ae2874a95319a11dff4c604afb6 (diff)
downloadglibc-7c6f9d53c1f57bb9b679fcdb39d2b5a9c63e46d3.tar.gz
glibc-7c6f9d53c1f57bb9b679fcdb39d2b5a9c63e46d3.tar.xz
glibc-7c6f9d53c1f57bb9b679fcdb39d2b5a9c63e46d3.zip
Move some things from sysdeps/unix to sysdeps/posix.
Diffstat (limited to 'sysdeps/posix')
-rw-r--r--sysdeps/posix/alarm.c50
-rw-r--r--sysdeps/posix/mkfifo.c29
-rw-r--r--sysdeps/posix/mkfifoat.c31
-rw-r--r--sysdeps/posix/nice.c52
-rw-r--r--sysdeps/posix/time.c41
-rw-r--r--sysdeps/posix/utime.c49
6 files changed, 252 insertions, 0 deletions
diff --git a/sysdeps/posix/alarm.c b/sysdeps/posix/alarm.c
new file mode 100644
index 0000000000..730f2c4c77
--- /dev/null
+++ b/sysdeps/posix/alarm.c
@@ -0,0 +1,50 @@
+/* Copyright (C) 1991,1992,1994,1997,2002,2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU 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 2.1 of the License, or (at your option) any later version.
+
+   The GNU 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 GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sys/time.h>
+
+/* Schedule an alarm.  In SECONDS seconds, the process will get a SIGALRM.
+   If SECONDS is zero, any currently scheduled alarm will be cancelled.
+   The function returns the number of seconds remaining until the last
+   alarm scheduled would have signaled, or zero if there wasn't one.
+   There is no return value to indicate an error, but you can set `errno'
+   to 0 and check its value after calling `alarm', and this might tell you.
+   The signal may come late due to processor scheduling.  */
+unsigned int
+alarm (seconds)
+     unsigned int seconds;
+{
+  struct itimerval old, new;
+  unsigned int retval;
+
+  new.it_interval.tv_usec = 0;
+  new.it_interval.tv_sec = 0;
+  new.it_value.tv_usec = 0;
+  new.it_value.tv_sec = (long int) seconds;
+  if (__setitimer (ITIMER_REAL, &new, &old) < 0)
+    return 0;
+
+  retval = old.it_value.tv_sec;
+  /* Round to the nearest second, but never report zero seconds when
+     the alarm is still set.  */
+  if (old.it_value.tv_usec >= 500000
+      || (retval == 0 && old.it_value.tv_usec > 0))
+    ++retval;
+  return retval;
+}
+libc_hidden_def (alarm)
diff --git a/sysdeps/posix/mkfifo.c b/sysdeps/posix/mkfifo.c
new file mode 100644
index 0000000000..70329bd12a
--- /dev/null
+++ b/sysdeps/posix/mkfifo.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU 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 2.1 of the License, or (at your option) any later version.
+
+   The GNU 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 GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+/* Create a named pipe (FIFO) named PATH with protections MODE.  */
+int
+mkfifo (const char *path, mode_t mode)
+{
+  dev_t dev = 0;
+  return __xmknod (_MKNOD_VER, path, mode | S_IFIFO, &dev);
+}
diff --git a/sysdeps/posix/mkfifoat.c b/sysdeps/posix/mkfifoat.c
new file mode 100644
index 0000000000..33fa6bde71
--- /dev/null
+++ b/sysdeps/posix/mkfifoat.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU 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 2.1 of the License, or (at your option) any later version.
+
+   The GNU 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 GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/stat.h>
+
+
+/* Create a new FIFO with permission bits MODE.  But interpret
+   relative PATH names relative to the directory associated with FD.  */
+int
+mkfifoat (fd, file, mode)
+     int fd;
+     const char *file;
+     mode_t mode;
+{
+  dev_t dev = 0;
+  return __xmknodat (_MKNOD_VER, fd, file, mode | S_IFIFO, &dev);
+}
diff --git a/sysdeps/posix/nice.c b/sysdeps/posix/nice.c
new file mode 100644
index 0000000000..b986ffbf30
--- /dev/null
+++ b/sysdeps/posix/nice.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 1992, 1996, 1997, 2001, 2002, 2006
+   Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU 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 2.1 of the License, or (at your option) any later version.
+
+   The GNU 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 GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/resource.h>
+
+/* Increment the scheduling priority of the calling process by INCR.
+   The superuser may use a negative INCR to decrement the priority.  */
+int
+nice (int incr)
+{
+  int save;
+  int prio;
+  int result;
+
+  /* -1 is a valid priority, so we use errno to check for an error.  */
+  save = errno;
+  __set_errno (0);
+  prio = getpriority (PRIO_PROCESS, 0);
+  if (prio == -1)
+    {
+      if (errno != 0)
+	return -1;
+      else
+	__set_errno (save);
+    }
+
+  result = setpriority (PRIO_PROCESS, 0, prio + incr);
+  if (result == -1)
+    {
+      if (errno == EACCES)
+	errno = EPERM;
+      return -1;
+    }
+  return getpriority (PRIO_PROCESS, 0);
+}
diff --git a/sysdeps/posix/time.c b/sysdeps/posix/time.c
new file mode 100644
index 0000000000..e026a384df
--- /dev/null
+++ b/sysdeps/posix/time.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 1991,92,97,2001,02 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU 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 2.1 of the License, or (at your option) any later version.
+
+   The GNU 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 GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stddef.h>		/* For NULL.  */
+#include <time.h>
+#include <sys/time.h>
+
+
+/* Return the current time as a `time_t' and also put it in *T if T is
+   not NULL.  Time is represented as seconds from Jan 1 00:00:00 1970.  */
+time_t
+time (t)
+     time_t *t;
+{
+  struct timeval tv;
+  time_t result;
+
+  if (__gettimeofday (&tv, (struct timezone *) NULL))
+    result = (time_t) -1;
+  else
+    result = (time_t) tv.tv_sec;
+
+  if (t != NULL)
+    *t = result;
+  return result;
+}
+libc_hidden_def (time)
diff --git a/sysdeps/posix/utime.c b/sysdeps/posix/utime.c
new file mode 100644
index 0000000000..a750ecc290
--- /dev/null
+++ b/sysdeps/posix/utime.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 1991,94,97,2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU 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 2.1 of the License, or (at your option) any later version.
+
+   The GNU 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 GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <utime.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+
+/* Set the access and modification times of FILE to those given in TIMES.
+   If TIMES is NULL, set them to the current time.  */
+int
+utime (file, times)
+     const char *file;
+     const struct utimbuf *times;
+{
+  struct timeval timevals[2];
+  struct timeval *tvp;
+
+  if (times != NULL)
+    {
+      timevals[0].tv_sec = (time_t) times->actime;
+      timevals[0].tv_usec = 0L;
+      timevals[1].tv_sec = (time_t) times->modtime;
+      timevals[1].tv_usec = 0L;
+      tvp = timevals;
+    }
+  else
+    tvp = NULL;
+
+  return __utimes (file, tvp);
+}
+libc_hidden_def (utime)