当前位置:网站首页>Advanced Programming in UNIX Environment - Chapter 2

Advanced Programming in UNIX Environment - Chapter 2

2022-08-06 07:51:57heart flower

1.引言

人们在UNIX编程环境和C程序设计语言的标准化方面已经做了很多工作.虽然UNIX应用程序在不同的UNIX操作系统版本之间进行移植相当容易,但是20世纪80年代UNIXVersion of types of surge and differences between them expand,Has led to many large users to call for standardization.
This chapter first reviews the past nearly25People inUNIXStandardization efforts to make,Then discuss theseUNIXThis chapter listed various programming standardsUNIXThe influence of the operating system to realize.All is an important part of standardization for each implementation must define restrictions for that,So we speak illustrate these limitations as well as various methods to determine their value.

2.UNIX标准化

(1)ISO C
1989年下半年,C程序设计语言的ANSI标准X3.159-1989得到批准,This standard is adopted as an international standardISO/IEC 9899:1990.ANSI是美国国家标准学会的缩写,It is on behalf of the members of the United States in the international organization for standardization.IECIs the abbreviation of international electronic technology committee.
ISO CStandard by nowISO/IEC的C程序设计语言国际标准工作组维护和开发,The working group is calledISO/IEC JTCI/SC22/WG14,简称WG14.ISO C标准的意图是提供C程序的可移植性,使其能适合于大量不同的操作系统,而不只是适合UNIX系统.此标准不仅定义了C程序设计语言的语法和语义,还定义了其标准库.Because all the presentUNIX系统都提供CStandards are defined in the library function,So the standard library is very important.
1999年,ISO C标准被更新,并被批准为ISO/IEC 9899:1999,它显著改善了对进行数值处理的应用软件的支持.除了对某些函数原型增加了关键字restrict外,This change does not affectPOSIX接口.restrict关键字告诉编译器,The pointer references can be optimized,The method is pointed out that pointer reference object in function can only be accessed through the pointer to.
1999年以来,以及公布了3个技术勘误来修正ISO C标准中的错误,分别在2001年,2004年和2007年公布.如同大多数标准一样,在批准标准和修改软件使其符合标准两者之间有一段时间延迟.随着供应商编译系统的不断演化,对最新ISO C标准的支持也就越来越多.
According to the standard definition of each header file can beISO CThe library is divided into24个区.POSIX.1Standard including the header files and other header files.从图2-1中可以看出,All of these header files in4中UNIXImplementations support.This chapter will be on this4中UNIXShow the implementation.
头文件

<assert.h>:验证程序断言
<complex.h>:The complex arithmetic operation support
<ctype.h>:Character classification and mapping support
<errno.h>:出错码
<float.h>:Floating-point constant and features
<inttypes.h>:The integer format transform
<iso646.h>:赋值,Relations and one yuan FuHong operation
<limits.h>:实现常量
<locale.h>:Localization category and related definition
<math.h>:数学函数,Type declarations and const
<setjmp.h>:非局部goto
<signal.h>:信号
<stdarg.h>:Variable length argument list
<stdbool.h>:布尔类型和值
<stddef.h>:标准定义
<stdint.h>:整型
<stdio.g>:标准IO库
<stdlib.h>:使用函数
<string.h>:字符串操作
<tgmath.h>:通用类型数学宏
<time.h>:时间和日期
<wchar.h>:Expand the multibyte and wide character support
<wctype.h>:宽Character classification and mapping support

(2)IEEE POSIX
POSIX是一个最初由IEEEThe family of standards set by the.POSIXRefers to the can refer to the operating system interface,它原来指的只是IEEE标准1003.1-1988,后来则扩展成包括很多标记为1003的标准及标准草案,如shellAnd use the program(1003.2).
1003.1Standard purpose is to promote the application in a variety ofUNIXThe portability between systems environment.它定义了"符合POSIX的"The operating system must provide various services.This standard has been adopted by many computer manufacturers.
由于1003.1Standard illustrates an interface, not an implementation,So do not distinguish between system calls and library functions.All routines in the standard are called the function.
2001年的1003.1Version has bigger difference with each big version before,It combines multiple1003.1的修正,1003.2标准以及single UNIX Specification第2Version number part.
2004年POSIX.1As the technology errata updated,2008Years made a more comprehensive changes,ISO在2009年进行发布.
POSIX.1Does not include the concept of super user,The provisions of the generation of some operation requirements"The appropriate priority".
(3)Single UNIX Specification
Single UNIX Specification是POSIX标准的一个超集,It defines some additional interface extensionPOSIX.1规范提供的功能.
POSIX.1中的X/openThe system interface options describes optional interface,Also defines the followingXSI的实现必须支持POSIX.1The optional part.These must support part includes:文件同步,Thread stack address and length property,Thread process synchronization and sharing_XOPEN_UNIX符号常量.只有遵循XSIThe implementation of the can be calledUNIX系统.
(4)FIPS
FIPS代表的是联邦信息处理标准,这一标准是由美国政府发布的,并由美国政府用于计算机系统的采购.

3.UNIX系统的历史

略…

4.标准和实现的关系

略…

5.限制

UNIXSystem implementation defines many magic number and const,Many of them, and be hard coded into the program,Or with specific technology to determine.Because of a large number of standardization work hard,There have been several kind of portable method used to determine whether the magic number and the concrete implementation defined limit.This is very help to improve theUNIXUnder the environment of software portability.
The following two types of limit is necessary:
①编译时限制(例如,What is the maximum short integer?)
②运行时限制(例如,How many letters are there in the file name characters)
Compile time limit can be defined in a header file.Program at compile time can include the header file.但是,Run time limit requires process calls a function to obtain the limiting value.
In addition some restrictions may be inherent in a given implementation of(Can therefore be statically defined in a file header),In another implementation may be changing(Need a runtime function call).An example of this type of limit is the maximum number of characters in the file name.SVR4之前的系统VDue to historical reasons only allow the file name contains the most14个字符,而源于BSDSystem will increase the as255.目前,大多数UNIX支持多文件系统类型,And each type has its own restrictions.File name what is the maximum length depends on the file file system,例如,In the root file system file name length limit may be14个字符,And in another file system file name length limit may be255个字符,This is an example of run time limit.
为了解决这类问题,提供了以下3种限制:
①编译时限制(头文件)
②Has nothing to do with the file or directory in the run time limit(sysconf)
③与文件或目录相关的运行时限制(pathconf和fpathconf函数).
使事情变得更加复杂的是,If a specific runtime restrictions on a given system does not change,It is statically defined in a header file,但是,If there is no will be defined in a header file,The application must call3个conf函数中的一个,To determine the runtime value.
(1)ISO C限制
ISO CDefine all the compile time limits are listed in the header file<limits.h>中,These restrictions constants in a given system will not change.第3Column is a list ofISO CMinimum acceptable values.这用于16For integer system,用1Won't say.第4Column is a list of32为整型Linux系统的值,用2的补码表示.注意,We didn't list the unsigned data type of the minimum,These values should be for the0.在64位系统中,其longA maximum of integer with the tablelong longA maximum of integer match.
示例:2-6
在这里插入图片描述
We will have a difference is whether the system provide a signed or unsigned character values.从2-6示例中的第4列可以看出,The specific system using signed character.从图中可以看出CHAR_MIN等于SCHAR_MIN,SCHAR_MAX等于SCHAR_MAX.If the system USES an unsigned character,则CHAR_MIN等于0,CHAR_MAX等于UCHAR_MAX.
在头文件<float.h>中,A group for floating point data types have similar definition.If the reader design a large number of floating point data types in a work,You should take a closer look at the file.
Should we have aISO C常量是FOPEN_MAX,This is the criterion for concrete implementation guarantee at the same time can openIOThe minimum number of flow,The value in the header file<stdio.h>中定义,其最小值是8.POSIX.1中的STREAM_MAX则应与FOPEN_MAX具有相同的值.
ISO C还在<stdio.h>中定义了常量TMP_MAX,这是由tmpnamFunction of the only file name the maximum number of.
虽然ISO C定义了常量FILENAME_MAX,But we should face using the const,因为POSIX.1Provides a better alternative const(NAME_MAX和PATH_MAX),We will soon introduce the const.
(2)POSIX限制
POSIX.1Defines a lot of design operating system implementation limit of const,遗憾的是,这是POSIX.1One part of which is the most confused.虽然POSIX.1Defines a lot of restrictions and const,We only care about and basicPOSIX.1Interface related part.These restrictions, and constants are divided into the following7类.
①数值限制:LONG_BIT,SSIZE_MAX和WORD_BIT.
②最小值:图2-8种的25个常量.
③最大值:_POSIX_ClOCKRES_MIN.
④运行时可以增加的值:CHARCLASS_NAME_MAX,COLL_WEIGHTS_MAX,LINE_MAX,NGROUPS_MAX和RE_DUP_MAX.
⑤The runtime constant value:图2-9的17个常量
⑥Other unchanged value:NL_ARGMAX,NL_MSGMAX,NL_SETMAX,NL_TEXTMAX
⑦The path name can prepare:FILESIZEBITS,LINK_MAX,MAX_CANON,MAX_INPUT,NAME_MAX,PATH_MAX,PIPE_BUF,SYMLINK_MAX
In these restrictions and constant,Some may be defined in the<limits.h>中,The rest can be defined on the specific terms and conditions,可不定义.
示例2-8:<limits.h>中POSIX.1最小值
在这里插入图片描述
遗憾的是,Some of these constant minimum value in practical application is too small.For example, at present in mostUNIX系统中,Each process can open files at the same time for more than20.另外,_POSIX_PATH_MAXThe minimum limit is255,这太小了,The path name may exceed this limit.This means that can't be used at compile time_POSIX_OPEN_MAX和_POSIX_PATHThe two constants as array length.
图2-8中的25A constant minimum value of each has a related implementation value,Its name is the picture2-8The name delete prefix_POSIX后构成的.没有_POSIX_Prefix name for a given specific implementation supports the same minimum value of the actual value.Problem is can't be make sure that all this25A value is realized in the<limits.h>头文件定义.
例如,A specific value may not be defined in the header file,其理由是,The real value of a given process may depend on the system of storage amount.If there is no defined in a header file them,Cannot use them at compile time as an array boundaries.所以,POSIX.1提供了3A runtime function to call,它们是:sysconfig,pathconf以及fpathconf.使用这3A function can be the realization of the actual runtime value.但是还有一个问题,Some of these values"May not be sure"(Logically infinite).
图2-9:The runtime constant value
在这里插入图片描述
(3)XSI限制
XSIDefine some constants of representative implementation limit.
①最小值:图2-10中列出了5个常量
②The runtime constant value(可能不确定):IOV_MAX和PAGE_SIZE
图2-10Lists the minimum.The last two constant values shows thatPOSIX.1The situation of the minimum value is too small,Supposedly the probably consider the embeddedPOSIX.1实现.为此,Single UNIXSpecification为符合XSISystem has increased the larger the minimum symbol.
图2-10:
在这里插入图片描述

原网站

版权声明
本文为[heart flower]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/218/202208060723403339.html

随机推荐