📄 posix.sgml
字号:
<!-- {{{ Banner -->
<!-- =============================================================== -->
<!-- -->
<!-- posix.sgml -->
<!-- -->
<!-- POSIX Compatibility -->
<!-- -->
<!-- =============================================================== -->
<!-- ####COPYRIGHTBEGIN#### -->
<!-- -->
<!-- =============================================================== -->
<!-- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. -->
<!-- This material may be distributed only subject to the terms -->
<!-- and conditions set forth in the Open Publication License, v1.0 -->
<!-- or later (the latest version is presently available at -->
<!-- http://www.opencontent.org/openpub/) -->
<!-- Distribution of the work or derivative of the work in any -->
<!-- standard (paper) book form is prohibited unless prior -->
<!-- permission obtained from the copyright holder -->
<!-- =============================================================== -->
<!-- -->
<!-- ####COPYRIGHTEND#### -->
<!-- =============================================================== -->
<!-- #####DESCRIPTIONBEGIN#### -->
<!-- -->
<!-- ####DESCRIPTIONEND#### -->
<!-- =============================================================== -->
<!-- }}} -->
<part id="posix-compatibility">
<title>eCos POSIX compatibility layer</title>
<chapter id="posix-standard-support">
<title>POSIX Standard Support</title>
<!-- {{{ Intro -->
<para>
eCos contains support for the POSIX Specification (ISO/IEC
9945-1)[POSIX].
</para>
<para>
POSIX support is divided between the POSIX and the FILEIO
packages. The POSIX package provides support for threads,
signals, synchronization, timers and message queues. The FILEIO
package provides support for file and device I/O. The two
packages may be used together or separately, depending on
configuration.
</para>
<para>
This document takes a functional approach to the POSIX
library. Support for a function implies that the data types and
definitions necessary to support that function, and the objects
it manipulates, are also defined. Any exceptions to this are
noted, and unless otherwise noted, implemented functions behave
as specified in the POSIX standard.
</para>
<para>
This document only covers the differences between the eCos
implementation and the standard; it does not provide complete
documentation. For full information, see the POSIX standard
[POSIX]. Online, the Open Group Single Unix
Specification [SUS2] provides complete documentation
of a superset of POSIX. If you have access to a Unix system with
POSIX compatibility, then the manual pages for this will be of
use. There are also a number of books available.
[Lewine] covers the process, signal, file and I/O
functions, while [Lewis1], [Lewis2],
[Nichols] and [Norton] cover Pthreads and
related topics (see Bibliography, xref). However, many of these
books are oriented toward using POSIX in non-embedded systems,
so care should be taken in applying them to programming under
eCos.
</para>
<para>
The remainder of this chapter broadly follows the structure
of the POSIX Specification. References to the appropriate
section of the Standard are included.
</para>
<para>
Omitted functions marked with “// TBA”
are potential candidates for later implementation.
</para>
<!-- }}} -->
<!-- {{{ Process Primitives -->
<sect1 id="posix-process-primitives">
<title>Process Primitives [POSIX Section 3]</title>
<!-- =================================================================== -->
<sect2>
<title>Functions Implemented</title>
<screen>
int kill(pid_t pid, int sig);
int pthread_kill(pthread_t thread, int sig);
int sigaction(int sig, const struct sigaction *act,
struct sigaction *oact);
int sigqueue(pid_t pid, int sig, const union sigval value);
int sigprocmask(int how, const sigset_t *set,
sigset_t *oset);
int pthread_sigmask(int how, const sigset_t *set,
sigset_t *oset);
int sigpending(sigset_t *set);
int sigsuspend(const sigset_t *set);
int sigwait(const sigset_t *set, int *sig);
int sigwaitinfo(const sigset_t *set, siginfo_t *info);
int sigtimedwait(const sigset_t *set, siginfo_t *info,
const struct timespec *timeout);
int sigemptyset(sigset_t *set);
int sigfillset(sigset_t *set);
int sigaddset(sigset_t *set, int signo);
int sigdelset(sigset_t *set, int signo);
int sigismember(const sigset_t *set, int signo);
unsigned int alarm( unsigned int seconds );
int pause( void );
unsigned int sleep( unsigned int seconds );
</screen>
</sect2>
<!-- =================================================================== -->
<sect2>
<title>Functions Omitted</title>
<screen>
pid_t fork(void);
int execl( const char *path, const char *arg, ... );
int execv( const char *path, char *const argv[] );
int execle( const char *path, const char *arg, ... );
int execve( const char *path, char *const argv[],
char *const envp[] );
int execlp( const char *path, const char *arg, ... );
int execvp( const char *path, char *const argv[] );
int pthread_atfork( void(*prepare)(void),
void (*parent)(void),
void (*child)() );
pid_t wait( int *stat_loc );
pid_t waitpid( pid_t pid, int *stat_loc,
int options );
void _exit( int status );
</screen>
</sect2>
<!-- =================================================================== -->
<sect2>
<title>Notes</title>
<itemizedlist>
<listitem>
<para>
Signal handling may be enabled or disabled with the
CYGPKG_POSIX_SIGNALS option. Since signals are used
by other POSIX components, such as timers, disabling signals will
disable those components too.
</para>
</listitem>
<listitem>
<para>
<emphasis>kill()</emphasis> and
<emphasis>sigqueue()</emphasis> may only take a
<emphasis role="strong">pid</emphasis> argument of zero,
which maps to the current process.
</para>
</listitem>
<listitem>
<para>
The <emphasis>SIGEV_THREAD</emphasis> notification type is
not currently implemented.
</para>
</listitem>
<listitem>
<para>
Job Control and Memory Protection signals are
not supported.
</para>
</listitem>
<listitem>
<para>
An extra implementation defined
<emphasis>si_code</emphasis> value,
<emphasis>SI_EXCEPT</emphasis>, is defined to
distinguish hardware generated exceptions from
others.
</para>
</listitem>
<listitem>
<para>
Extra signals are defined:
_SIGTRAP_,_SIGIOT_,
_SIGEMT_, and _SIGSYS_. These are
largely to maintain compatibility with the signal numbers used by
GDB.
</para>
</listitem>
<listitem>
<para>
Signal delivery may currently occur at unexpected places in some
API functions. Using <emphasis>longjmp()</emphasis> to transfer
control out of a signal handler may result in the interrupted
function not being able to complete properly. This may result in
later function calls failing or deadlocking.
</para>
</listitem>
</itemizedlist>
</sect2>
</sect1>
<!-- }}} -->
<!-- {{{ Process Environment -->
<sect1 id="posix-process-environment">
<title>Process Environment [POSIX Section 4]</title>
<!-- =================================================================== -->
<sect2>
<title>Functions Implemented</title>
<screen>
int uname( struct utsname *name );
time_t time( time_t *tloc );
char *getenv( const char *name );
int isatty( int fd );
long sysconf( int name );
</screen>
</sect2>
<!-- =================================================================== -->
<sect2>
<title>Functions Omitted</title>
<screen>
pid_t getpid( void );
pid_t getppid( void );
uid_t getuid( void );
uid_t geteuid( void );
gid_t getgid( void );
gid_t getegid( void );
int setuid( uid_t uid );
int setgid( gid_t gid );
int getgroups( int gidsetsize, gid_t grouplist[] );
char *getlogin( void );
int getlogin_r( char *name, size_t namesize );
pid_t getpgrp( void );
pid_t setsid( void );
int setpgid( pid_t pid, pid_t pgid );
char *ctermid( char *s);
char *ttyname( int fd ); // TBA
int ttyname_r( int fd, char *name, size_t namesize); // TBA
clock_t times( struct tms *buffer ); // TBA
</screen>
</sect2>
<!-- =================================================================== -->
<sect2>
<title>Notes</title>
<itemizedlist>
<listitem>
<para>The fields of the <emphasis>utsname</emphasis>
structure are initialized as follows:
<screen>
sysname “eCos”
nodename “” (gethostname() is currently not available)
release Major version number of the kernel
version Minor version number of the kernel
machine “” (Requires some config tool changes)
</screen>
</para>
<para>
The sizes of these strings are defined by
CYG_POSIX_UTSNAME_LENGTH and
CYG_POSIX_UTSNAME_NODENAME_LENGTH. The
latter defaults to the value of the former, but may also
be set independently to accommodate a longer node name.
</para>
</listitem>
<listitem>
<para>
The <emphasis>time()</emphasis> function is currently
implemented in the C library.
</para>
</listitem>
<listitem>
<para>A set of environment strings may be defined at configuration
time with the CYGDAT_LIBC_DEFAULT_ENVIRONMENT
option. The application may also define an environment by direct
assignment to the <emphasis role="strong">environ</emphasis>
variable.
</para>
</listitem>
<listitem>
<para>
At present <emphasis>isatty()</emphasis> assumes that
any character device is a tty and that all other devices are not
ttys. Since the only kind of device that eCos currently supports
is serial character devices, this is an adequate
distinction.
</para>
</listitem>
<listitem>
<para>
All system variables supported by sysconf will yield a
value. However, those that are irrelevant to eCos will
either return the default minimum defined in
<filename><limits.h></filename>,
or zero.
</para>
</listitem>
</itemizedlist>
</sect2>
</sect1>
<!-- }}} -->
<!-- {{{ Files and Directories -->
<sect1 id="posix-files-and-directories">
<title>Files and Directories [POSIX Section 5]</title>
<!-- =================================================================== -->
<sect2>
<title>Functions Implemented</title>
<screen>
DIR *opendir( const char *dirname );
struct dirent *readdir( DIR *dirp );
int readdir_r( DIR *dirp, struct dirent *entry,
struct dirent **result );
void rewinddir( DIR *dirp );
int closedir( DIR *dirp );
int chdir( const char *path );
char *getcwd( char *buf, size_t size );
int open( const char * path , int oflag , ... );
int creat( const char * path, mode_t mode );
int link( const char *existing, const char *new );
int mkdir( const char *path, mode_t mode );
int unlink( const char *path );
int rmdir( const char *path );
int rename( const char *old, const char *new );
int stat( const char *path, struct stat *buf );
int fstat( int fd, struct stat *buf );
int access( const char *path, int amode );
long pathconf(const char *path, int name);
long fpathconf(int fd, int name);
</screen>
</sect2>
<!-- =================================================================== -->
<sect2>
<title>Functions Omitted</title>
<screen>
mode_t umask( mode_t cmask );
int mkfifo( const char *path, mode_t mode );
int chmod( const char *path, mode_t mode ); // TBA
int fchmod( int fd, mode_t mode ); // TBA
int chown( const char *path, uid_t owner, gid_t group );
int utime( const char *path, const struct utimbuf *times ); // TBA
int ftruncate( int fd, off_t length ); // TBA
</screen>
</sect2>
<!-- =================================================================== -->
<sect2>
<title>Notes</title>
<itemizedlist>
<listitem>
<para>
If a call to <function>open()</function> or <function>creat()</function> supplies
the third _mode_ parameter, it will
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -