Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
Macros | Functions
unistd.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include "kconfig.h"
Include dependency graph for unistd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MQ_PRIO_MAX   _MQ_PRIO_MAX
 
#define STDIN_FILENO   0 /* Standard input file descriptor */
 
#define STDOUT_FILENO   1 /* Standard output file descriptor */
 
#define STDERR_FILENO   2 /* Standard error file descriptor */
 
#define _SC_ARG_MAX   0
 
#define _SC_CLK_TCK   2
 
#define _SC_OPEN_MAX   4
 
#define _SC_PAGESIZE   8
 
#define sysconf   _sysconf
 Report a value of the system that is decided when it is built. More...
 
#define F_OK   0 /* The file exists */
 
#define X_OK   1 /* The file can be executed */
 
#define W_OK   2 /* The file can be written */
 
#define R_OK   4 /* The file can be read */
 

Functions

unsigned int sleep (unsigned int seconds)
 To cause the calling thread to sleep either until the number of real-time seconds specified in seconds have elapsed or until a signal arrives which is not ignored. More...
 
int usleep (useconds_t usec)
 Suspend execution of the calling thread for a given time in microseconds. More...
 
int close (int fd)
 Close a file descriptor, so that it no longer refers to any file and may be reused. More...
 
int dup (int oldfd)
 Create a copy of the file descriptor oldfd, using the lowest-numbered unused file descriptor for the new descriptor. More...
 
int dup2 (int oldfd, int newfd)
 Perform the same task as dup(), but use the file descriptor number specified by newfd. More...
 
int pipe (int pipefd[2])
 Create a pipe, a stream that is written to through one descriptor and read from through the other. More...
 
pid_t vfork (void)
 Create a child process. Tenok runs every task from the image it booted and has no way to make another, so the call always fails. More...
 
pid_t fork (void)
 Create a child process, the way vfork() does not either. More...
 
pid_t setsid (void)
 Start a session. Tenok has the one console and no sessions to give it out to. More...
 
int execve (const char *pathname, char *const argv[], char *const envp[])
 Replace the running program with the one the pathname names. No file of Tenok is in a format the system can execute, so the call always fails. More...
 
int execvp (const char *file, char *const argv[])
 Replace the running program with the one found by searching PATH for the file, the way execve() does. More...
 
ssize_t read (int fd, void *buf, size_t count)
 Attempt to read up to count bytes from file descriptor fd into the buffer starting at buf. More...
 
ssize_t write (int fd, const void *buf, size_t count)
 Write up to count bytes from the buffer starting at buf to the file referred to by the file descriptor fd. More...
 
off_t lseek (int fd, long offset, int whence)
 Reposition the file offset of the open file description associated with the file descriptor fd. More...
 
pid_t getpid (void)
 Return the ID of the calling task. More...
 
pid_t getppid (void)
 Return the ID of the task that started the calling one. Every task of Tenok is started by the one that brings the system up. More...
 
char * getcwd (char *buf, size_t size)
 Get current working directory. More...
 
int chdir (const char *path)
 Change working directory. More...
 
int unlink (const char *pathname)
 Delete a name from the file system. More...
 
int rmdir (const char *pathname)
 Delete a directory, which must be empty. More...
 
long sysconf (int name)
 
int isatty (int fd)
 Tell whether a descriptor refers to a terminal. More...
 
int access (const char *pathname, int mode)
 Check whether the calling task can reach a file the way it asks. More...
 
uid_t getuid (void)
 Report the user a task runs as, which on Tenok is always root. More...
 
int setuid (uid_t uid)
 Become the user of the given identifier. Tenok runs as the one user it has, so only that one can be become. More...
 
int seteuid (uid_t uid)
 Become the effective user of the given identifier, the way setuid() does. More...
 
uid_t geteuid (void)
 
gid_t getgid (void)
 Report the group a task runs as, which on Tenok is always root. More...
 
int setgid (gid_t gid)
 Join the group of the given identifier. Tenok has the one group, so only that one can be joined. More...
 
int setegid (gid_t gid)
 Join the effective group of the given identifier, the way setgid() does. More...
 
gid_t getegid (void)
 
int getgroups (int size, gid_t list[])
 Report the supplementary groups of the task. Tenok has one group and root is in it, so there is never a supplementary one. More...
 
int link (const char *oldpath, const char *newpath)
 Give a file a second name. Tenok gives a file one name. More...
 
int symlink (const char *target, const char *linkpath)
 Make a name that stands for another. Tenok has no symbolic link. More...
 
int readlink (const char *pathname, char *buf, size_t bufsiz)
 Read what a symbolic link stands for. Nothing a path of Tenok names is one. More...
 
int fchdir (int fd)
 Change the working directory to the one the descriptor names. Tenok keeps no way back from a descriptor to the name it was opened by. More...
 
int ttyname_r (int fd, char *buf, size_t buflen)
 Name the terminal the descriptor is open on. Tenok keeps no way back from a descriptor to the name it was opened by. More...
 
int chroot (const char *path)
 Make the given directory the root. The root of Tenok is the whole of what it mounted, with nothing outside to be shut away from. More...
 
int chown (const char *pathname, uid_t owner, gid_t group)
 Replace the owner of a file. Tenok has one user, so only a request that names it can be granted. More...
 
int lchown (const char *pathname, uid_t owner, gid_t group)
 Replace the owner of a file without following a symbolic link. Tenok has no symbolic link, so this is chown() More...
 

Macro Definition Documentation

◆ sysconf

#define sysconf   _sysconf

Report a value of the system that is decided when it is built.

Parameters
nameOne of the SC values.
Return values
longThe value on success and -1 when Tenok has no such value, with the reason left in errno.

Function Documentation

◆ access()

int access ( const char *  pathname,
int  mode 
)

Check whether the calling task can reach a file the way it asks.

Parameters
pathnameThe pathname of the file to check.
modeF_OK, or the R_OK, W_OK and X_OK to check for.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ chdir()

int chdir ( const char *  path)

Change working directory.

Parameters
pathPathname of the new working directory.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ chown()

int chown ( const char *  pathname,
uid_t  owner,
gid_t  group 
)

Replace the owner of a file. Tenok has one user, so only a request that names it can be granted.

Parameters
pathnameThe pathname of the file.
ownerThe user to give it to, or -1 to leave it alone.
groupThe group to give it to, or -1 to leave it alone.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ chroot()

int chroot ( const char *  path)

Make the given directory the root. The root of Tenok is the whole of what it mounted, with nothing outside to be shut away from.

Parameters
pathThe directory to make the root.
Return values
int-1 with errno set to ENOSYS.

◆ close()

int close ( int  fd)

Close a file descriptor, so that it no longer refers to any file and may be reused.

Parameters
fdThe file descriptor to provide.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ dup()

int dup ( int  oldfd)

Create a copy of the file descriptor oldfd, using the lowest-numbered unused file descriptor for the new descriptor.

Parameters
oldfdThe file descriptor to duplicate.
Return values
intThe new file descriptor on success and -1 on error, with the reason left in errno.

◆ dup2()

int dup2 ( int  oldfd,
int  newfd 
)

Perform the same task as dup(), but use the file descriptor number specified by newfd.

Parameters
oldfdThe file descriptor to duplicate.
newfdThe number to specify the new file descriptor.
Return values
intThe new file descriptor on success and -1 on error, with the reason left in errno.

◆ execve()

int execve ( const char *  pathname,
char *const  argv[],
char *const  envp[] 
)

Replace the running program with the one the pathname names. No file of Tenok is in a format the system can execute, so the call always fails.

Parameters
pathnameThe pathname of the program.
argvThe arguments to hand the program.
envpThe environment to hand the program.
Return values
int-1 with errno set to ENOEXEC.

◆ execvp()

int execvp ( const char *  file,
char *const  argv[] 
)

Replace the running program with the one found by searching PATH for the file, the way execve() does.

Parameters
fileThe name of the program to search for.
argvThe arguments to hand the program.
Return values
int-1 with errno set to ENOEXEC.

◆ fchdir()

int fchdir ( int  fd)

Change the working directory to the one the descriptor names. Tenok keeps no way back from a descriptor to the name it was opened by.

Parameters
fdThe descriptor of the directory.
Return values
int-1 with errno set to ENOSYS.

◆ fork()

pid_t fork ( void  )

Create a child process, the way vfork() does not either.

Return values
pid_t-1 with errno set to ENOSYS.

◆ getcwd()

char* getcwd ( char *  buf,
size_t  size 
)

Get current working directory.

Parameters
bufBuffer space for storing path of the current working space.
sizeSize of the buffer space.
bufBuffer space for storing path of the current working space, or a null pointer to ask for one that free() takes back.
Return values
char*: The buffer on success and a null pointer on error, with the reason left in errno.

◆ getgid()

gid_t getgid ( void  )

Report the group a task runs as, which on Tenok is always root.

Return values
gid_tAlways 0.

◆ getgroups()

int getgroups ( int  size,
gid_t  list[] 
)

Report the supplementary groups of the task. Tenok has one group and root is in it, so there is never a supplementary one.

Parameters
sizeHow many the list holds.
listFor returning the groups.
Return values
intAlways 0.

◆ getpid()

pid_t getpid ( void  )

Return the ID of the calling task.

Return values
pid_tThe task ID.

◆ getppid()

pid_t getppid ( void  )

Return the ID of the task that started the calling one. Every task of Tenok is started by the one that brings the system up.

Return values
pid_tAlways 1.

◆ getuid()

uid_t getuid ( void  )

Report the user a task runs as, which on Tenok is always root.

Return values
uid_tAlways 0.

◆ isatty()

int isatty ( int  fd)

Tell whether a descriptor refers to a terminal.

Parameters
fdThe file descriptor to provide.
Return values
intOne when it does, and zero when it does not, with the reason left in errno.

◆ lchown()

int lchown ( const char *  pathname,
uid_t  owner,
gid_t  group 
)

Replace the owner of a file without following a symbolic link. Tenok has no symbolic link, so this is chown()

Parameters
pathnameThe pathname of the file.
ownerThe user to give it to, or -1 to leave it alone.
groupThe group to give it to, or -1 to leave it alone.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ link()

int link ( const char *  oldpath,
const char *  newpath 
)

Give a file a second name. Tenok gives a file one name.

Parameters
oldpathThe file to name again.
newpathThe name to give it.
Return values
int-1 with errno set to ENOSYS.

◆ lseek()

off_t lseek ( int  fd,
long  offset,
int  whence 
)

Reposition the file offset of the open file description associated with the file descriptor fd.

Parameters
fdThe file descriptor to provide.
offsetThe new offset to the position specified by whence.
whenceThe start position of the new offset.
Return values
off_tThe new offset on success and -1 on error, with the reason left in errno.

◆ pipe()

int pipe ( int  pipefd[2])

Create a pipe, a stream that is written to through one descriptor and read from through the other.

Parameters
pipefdWhere to store the two descriptors, the read end first and the write end second.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ read()

ssize_t read ( int  fd,
void *  buf,
size_t  count 
)

Attempt to read up to count bytes from file descriptor fd into the buffer starting at buf.

Parameters
fdThe file descriptor to provide.
bufThe memory space for storing read data.
countThe number of bytes to read.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ readlink()

int readlink ( const char *  pathname,
char *  buf,
size_t  bufsiz 
)

Read what a symbolic link stands for. Nothing a path of Tenok names is one.

Parameters
pathnameThe name to read.
bufWhere to put what it stands for.
bufsizThe room there is for it.
Return values
int-1 with errno set to EINVAL, which is what POSIX says of a name that is not a symbolic link.

◆ rmdir()

int rmdir ( const char *  pathname)

Delete a directory, which must be empty.

Parameters
pathnameThe pathname of the directory to remove.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ setegid()

int setegid ( gid_t  gid)

Join the effective group of the given identifier, the way setgid() does.

Parameters
gidThe group to join.
Return values
int0 for the group Tenok runs as, and -1 with errno set to EPERM for any other.

◆ seteuid()

int seteuid ( uid_t  uid)

Become the effective user of the given identifier, the way setuid() does.

Parameters
uidThe user to become.
Return values
int0 for the user Tenok runs as, and -1 with errno set to EPERM for any other.

◆ setgid()

int setgid ( gid_t  gid)

Join the group of the given identifier. Tenok has the one group, so only that one can be joined.

Parameters
gidThe group to join.
Return values
int0 for the group Tenok runs as, and -1 with errno set to EPERM for any other.

◆ setsid()

pid_t setsid ( void  )

Start a session. Tenok has the one console and no sessions to give it out to.

Return values
pid_t-1 with errno set to ENOSYS.

◆ setuid()

int setuid ( uid_t  uid)

Become the user of the given identifier. Tenok runs as the one user it has, so only that one can be become.

Parameters
uidThe user to become.
Return values
int0 for the user Tenok runs as, and -1 with errno set to EPERM for any other.

◆ sleep()

unsigned int sleep ( unsigned int  seconds)

To cause the calling thread to sleep either until the number of real-time seconds specified in seconds have elapsed or until a signal arrives which is not ignored.

Parameters
secondsThe sleep seconds to provide.
Return values
int0 on success and nonzero error number on error.

◆ symlink()

int symlink ( const char *  target,
const char *  linkpath 
)

Make a name that stands for another. Tenok has no symbolic link.

Parameters
targetWhat the name would stand for.
linkpathThe name to make.
Return values
int-1 with errno set to ENOSYS.

◆ ttyname_r()

int ttyname_r ( int  fd,
char *  buf,
size_t  buflen 
)

Name the terminal the descriptor is open on. Tenok keeps no way back from a descriptor to the name it was opened by.

Parameters
fdThe descriptor.
bufWhere to put the name.
buflenThe room there is for it.
Return values
intENOSYS.

◆ unlink()

int unlink ( const char *  pathname)

Delete a name from the file system.

Parameters
pathnameThe pathname of the file to remove.
Return values
int0 on success and -1 on error, with the reason left in errno.

◆ usleep()

int usleep ( useconds_t  usec)

Suspend execution of the calling thread for a given time in microseconds.

Parameters
usecThe sleep microseconds to provide.
Return values
int0 on success and nonzero error number on error.

◆ vfork()

pid_t vfork ( void  )

Create a child process. Tenok runs every task from the image it booted and has no way to make another, so the call always fails.

Return values
pid_t-1 with errno set to ENOSYS.

◆ write()

ssize_t write ( int  fd,
const void *  buf,
size_t  count 
)

Write up to count bytes from the buffer starting at buf to the file referred to by the file descriptor fd.

Parameters
fdThe file descriptor to provide.
bufThe data to write.
countThe number of bytes to write.
Return values
int0 on success and -1 on error, with the reason left in errno.