POSIX and ANSI C

Source: Internet
Author: User
Tags mathematical constants mathematical functions
Document directory
  • Standard (ansi c, POSIX, svid, xpg ,...)
  • Online Documentation (man, info, how-,...)
  • Storage location of library and header files
Standard (ansi c, POSIX, svid, xpg ,...)
  • Ansi c: This is the C language standard set by ANSI (US National Standards Agency) in 1989.
    It was later accepted as a standard by ISO (International Organization for Standardization) and therefore known as iso c.
    Ansi c aims to provide portability guarantee for C Programs on various operating systems, not limited to Unix.
    This standard not only defines the language and semantics of the C programming language, but also defines a standard library. This library can be based on
    The header file is divided into 15 parts, including: character type (<ctype. h>), error code (<errno. h> ),
    Floating Point constants (<float. h>), mathematical constants (<math. h>), standard definitions (<stddef. h> ),
    Standard I/O (<stdio. h>), tool functions (<stdlib. h>), string operations (<string. h> ),
    Time and date (<time. h>), variable parameter table (<stdarg. h>), signal (<signal. h> ),
    Non-local jump (<setjmp. h>), local information (<local. h>), program assertions (<assert. h>)
    And so on.
  • POSIX: The standard family originally developed by IEEE, which has been accepted by ISO as an international standard. Specific content of this Standard
    See 1.1.3. Posix.1 and posix.2 define POSIX-Compatible C-language system interfaces.
    And shell and tool standards. These two standards are commonly mentioned. POSIX indicates the portable operating system interface (POSIX ).
    Such as UNIX ). Institute of Electrical and Electronics Engineers (IEEE)
    The POSIX standard was initially developed to improve the portability of applications in UNIX environments. However, POSIX is not limited to Unix.
    Many other operating systems, such as DEC OpenVMS and Microsoft Windows NT, support the POSIX standard, especially
    IEEE Std. 1003.1-1990 (revised in 1995) or posix.1, posix.1 provides source code-Level C language application programming
    APIs are provided to operating system service programs, such as reading and writing files. Posix.1 has been
    Accepted by standards organization, ISO) and named as ISO/IEC 9945-1: 1990 standard.

  • Svid: System V interface description. The System V interface description (svid) describes at & t unix System V Operations.
    The system documentation is an extended superset of POSIX standards.
  • Xpg: X/Open portability guide. X/Open portability Guide (published by X/Open Company, Ltd ),
    Is a more general standard than POSIX. X/open has the Unix copyright, while xpg specifies to become a Unix
    The operating system must meet the requirements.

Glibc

As we all know, C language does not provide built-in support for common operations, such as input/output, memory management, and string operations.
On the contrary, these functions are generally provided by the standard "function library. The gnu c function library, glibc, is the most important function in Linux.
Function library, which defines all the library functions specified by the iso c standard, and is composed of POSIX or other UNIX operating systems.
Additional features specified by the system Variants include extensions related to the GNU system. Currently, glibc 2.0 is used in popular Linux systems.
And later versions. Glibc is based on the following standards:

  • Iso c: International Standard for the C programming language (ansi c.
  • POSIX: gnu c function library implements the ISO/IEC 9945-1: 1996 (POSIX system application programming interface,
    Posix.1) specifies all functions. This standard is an extension of iso c, including the original file system interface
    Language, device-related terminal control functions, and process control functions. At the same time, the gun C function library also supports
    ISO/IEC 9945-2: 1993 (POSIX shell and tool standard, namely posix.2) specified function,
    These include functions used to process regular expressions and pattern matching.
  • Berkeley UNIX: BSD and SunOS. The gnu c function library defines functions that are not standardized in Some UNIX versions,
    In particular, 4.2 BSD, 4.3 BSD, 4.4 bsd unix systems (I .e. "Berkeley UNIX") and "SunOS"
    (The popular 4.2 BSD variant contains some UNIX System V functions ). BSD functions include
    Symbolic Links, select functions, BSD signal processing functions, and sockets.
  • Svid: System V interface description. The gnu c function library defines a majority of objects specified by the svid but not Iso c.
    And POSIX. Supported functions from System V include inter-process communication and shared memory,
    Hsearch and drand48 Function Families, fmtmsg, and some mathematical functions.
  • Xpg: X/Open portability guide. The gnu c function library follows the X/Open portability Guide (Issue 4.2)
    And all xsi (x/open system interfaces) compatible with system extensions, while also following all x/Open Unix
    Extension.

System Call

A system call is an interface provided by the operating system to external programs. In C, the operating system calls
Function calling is completed because these functions encapsulate the details of system calls, including the system call entry, parameters, and
The returned value is implemented in the C-language function call process. In Linux, system call functions are defined in glibc.

When talking about system calling, pay attention to the following points:

  • A system call function usually returns 0 when the call succeeds, and a non-zero value when the call fails. If you want to check the cause of failure
    To determine the value of the global variable errno, errno contains the error code.
  • The returned data of many system calls is usually transmitted through reference parameters. In this case, you must pass
    The buffer address, and the returned data is saved in the buffer.
  • It cannot be considered that the system calls functions more efficiently than other functions. Note that system calling is time-consuming.
    .

System calls will be detailed later.

Online Documentation (man, info, how-to,...) 1. Man

Man, or manunal, is an electronic version of the UNIX System Manual. According to habits, UNIX system manuals are generally divided
Different sections (or sections, that is, sections), each section describes different system content. The current sections are divided as follows:

  1. Command: Common USER command
  2. System Call: kernel interface
  3. Function library call: Functions in the common function library
  4. Special files: special files in the/dev directory
  5. File Format and conventions:/etc/passwd and other file formats
  6. Game.
  7. Miscellaneous and conventions: Miscellaneous content such as standard file system layout and manual page Structure
  8. System Management commands.
  9. Kernel routine: Non-Standard Manual section. It facilitates Linux kernel development and includes

Other manual sections:

  • L: PostgreSQL database commands
  • N: Tcl/tk command

The manual page is generally stored in the/usr/man directory, where each sub-directory (such as Man1, Man2,..., manl, Mann)
Contains different manual sections. Run the man command to view the manual page.

Man command line:
MAN [-acdffhkktww] [-M system] [-P string] [-C config_file] [-M path] [-P
Pager] [-s section_list] [section] Name

Common command lines:
$ Man open
$ MAN 7 man
$ Man./myman.3

2. Info

Most software development tools in Linux are from the GNU project of the Free Software Foundation.
The online documents of parts are all in the form of info files. The info program is a GNU hypertext help system.

The info document is generally stored in the/usr/info directory. Run the info command to view the info document.

To run info, enter info at the shell prompt or Press ESC-X and info in GNU Emacs.

Info helps the system to display a topic directory on the initial screen. You can move the cursor over the topic menu with * and press Enter.
Enter the topic, or enter M, followed by the name of the topic menu. For example, you can type M and then type GCC.
Go to the GCC topic.
If you want to jump between topics, you must remember the following command keys:
* N: jump to the next node of the node;
* P: Jump to the previous node of the node;
* M: Specify the menu name and select another node;
* F: Enter the cross-reference topic;
* L: Enter the last node in the window;
* Tab: jump to the next hypertext link in the window;
* RET: hypertext link at the cursor;
* U: Go to the previous topic;
* D: Return to the initial node directory of info;
* H: Call up the info tutorial;
* Q: Exit info.

# DEMO #

3. How-

Another form of online documentation for your reference is howto files, which are located in the/usr/doc/howto directory of the system.
The file names of howto files all have a-howto suffix and are all text files.

Each howto file contains information about one aspect of Linux, such as the hardware it supports or how to create a boot disk.

To view these files, go to the/usr/doc/howto directory and run the more command in the following format:
$ CD/usr/doc/howto; moreTopic-name-Howto

In addition, howto documents also contain files in other formats, such as HTML and PS, stored in/usr/doc/howto/other-formats.

4. Miscellaneous

The Linux kernel documentation is generally included in the kernel source code. The directory is as follows:/usr/src/Linux-2.x.x/Documentation

The/usr/doc directory contains a large number of Descriptive documents related to specific software or function libraries.

Library and header file storage location 1. function library
  • /Lib: required shared library
  • /Usr/lib: Standard shared library and static library
  • /Usr/i486-linux-libc5/lib: libc5 compatibility function library
  • /Usr/x11r6/lib: x11r6 function library
  • /Usr/local/lib: Local function library
2. header files
  • /Usr/include: System header file
  • /Usr/local/include: Local header file

POSIX has now developed into a very large standard family, and some parts are under development. Table 1-1 provides the POSIX standard
Important components. POSIX is interchangeable with IEEE 1003 and 2003 family standards. Except 1003.1, 1003 and 2003
Families are also included in the table.

1-1 important components of POSIX standards

1003.0

Manage the POSIX open system environment (OSE ). IEEE passed this standard in 1995.
The ISO version is ISO/IEC 14252: 1996.

1003.1

Widely accepted and used for source code-level portability standards. 1003.1 provide a C language for the operating system
Use programming APIs ). IEEE and ISO have passed this standard in 1990, and IEEE passed this standard in 1995
The standard was revised.

1003.1b

A standard for Real-Time Programming (previous p1003.4 or posix.4 ). This standard was set in 1993
Passed by IEEE and merged into ISO/IEC 9945-1.

1003.1c

A standard for threads (code segments currently executed in a program. Previously p1993.4 or posix.4
This standard was adopted by IEEE in 1995 and is classified as ISO/IEC 9945-1: 1996.

1003.1 GB

A standard for Protocol-independent interfaces that enable an application to communicate with another application over the network
Communication. In 1996, IEEE passed this standard.

1003.2

A standard used for shell and tool software. They are the command processors required by the operating system.
And tool programs.
In 1992, IEEE passed this standard. ISO has also passed this standard (ISO/IEC 9945-2: 1993 ).

1003.2d

Improved 1003.2 standards.

1003.5

An API is equivalent to 1003.1 of ADA languages. In 1992, IEEE passed this standard.
It was revised on 1997. ISO has also passed this standard.

1003.5b

A Ada Language API equivalent to 1003.1b (Real-time extension. Both IEEE and ISO have passed
This standard. The ISO standard is ISO/IEC 14519: 1999.

1003.5c

An Ada Language API equivalent to 1003.1q (Protocol Independent interface. In 1998,
IEEE has passed this standard. ISO has also passed this standard.

1003.9

An API equivalent to 1003.1 In the Fortran language. In 1992, IEEE passed this standard,
It was re-confirmed on 1997. ISO has also passed this standard.

1003.10

A standard for application environment profile (AEP.
In 1995, IEEE passed this standard.

1003.13

A standard for the application environment framework mainly targets real-time applications using POSIX interfaces.
In 1998, IEEE passed this standard.

1003.22

A security framework guide for POSIX.

1003.23

A guide for user organization is mainly used to guide user development and use to support operation requirements.
Open System Environment (OSE) Framework

2003

For the purpose of specifying and using POSIX-compliant testing methods
A standard. In 1997, IEEE passed this standard.

2003.1

This Standard specifies certain conditions that the provider of POSIX testing methods for 1003.1 will provide.
In 1992, IEEE passed this standard.

2003.2

A test method that is used to check compliance with IEEE 1003.2 (shell and tool APIs) is defined.
Standard. In 1996, IEEE passed this standard.

In addition to the 1003 and 2003 families, there are several other IEEE standards, such as 1224 and 1228.
It also provides APIs for developing portable applications. For the latest information about the IEEE Standard, visit
IEEE Standard Homepage
Http://standard.ieee.org /.
For POSIX standard overview, visit the Web site

Http://standards.ieee.org/reading/ieee/stad_public/description/posix /.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.