关于glibc与BSD libc的比较

unix-ilke系统真的是百家争鸣。之前知道很多很多不同的发行版。也曾经因为在solaris下做过一些开发,从而接触过BSD体系的皮毛。最近一直在做Android下的开发,稍微关注了一下其中的Bionic,一如google申明的它是植根于BSD的libc体系的。因为大部分的工作都是使用glibc进行开发,处于好奇关注了下两者的区别。


以下内容是从一个邮件组里面所引用,因为是比较老的信息,只能作为参考。如果需要做port的考量或者做搭建新系统的考量,一定还得对没项的最新情况进行调查。


总体而言,两者针对的平台体系不太一样,或多或少会有一些底层interface的差别。对我们大部分的开发者而言,是在某一平台体系下开发时,如果需要用到其它体系下有的好的功能或者interface,就需要查找考量是做porting还是应该从头实现!!

glibc vs BSD libc

http://lists.debian.org/debian-bsd/2003/01/msg00013.html


Why is it important for debian BSD to sum up the differences in BSD libc and glibc?
What I have learned from this thread (and from porting apps from linux to NetBSD and Solaris):

- there are differences between the libcs of these systems.
- sometimes they hurt during ports, most of the time, they don´t hurt
- the dominance of glibc-based linux has forced IBM and SUN to supply linux programming
  interfaces. This might happen in the BSD world in the future.
- for the debian/BSD project on the sparc it seems to be better to stick to BSD libc
  (we keep in track with alpha and intel ports)

So, coming back to the main topic: how did the NetBSD/intel people overcome these difficulties
caused by bsd libc/glibc?


1.
License
glibc :LGPL License
BSD libc:BSD

2.
glibc support for standards:
ANSI C(ISO C)
POSIX (Pthreads support)
SYSTEM V
(Eg:
Malloc tunable parameter(mallopt)
Extensions :
Statistics for storage allocation with malloc(mallinfo)
_tolower() and _toupper() supported.
)
Berkely UNIX
(Eg:
BSD Signal handling
BSD wait
Symbolic links
Sockets
)

BSD libc supports:
ANSI C
pthreads as per POSIX.1 std
Berkely UNIX

If it's an 'extension', then it's not 'standard' and not worth using
as a point of comparison.  Basically, most of the things you list as
"not supported" by BSD are better stated as being GNU-specific
extensions that are non-standard and therefore incompatible with the
rest of the world.


3.Portabilityglibc:Portable to more than one Kernel and hence largeBSD libc:Don?t attempt to be portable across kernels and hence smaller.
I do not see the logic.  If you are speaking about lines of code in
the distribution, I may agree, however, this does not speak to the
size of the generated binary, which seems to me to be what you are
referring to.

4.Error Reporting facility(Eg:perror,strerror)glibc:SupportedBSD libc:Supported5.Memory AllocationBasic Dynamic memory allocation (malloc () and free())Changing the size of previously allocated memory(realloc()Allocating and Clearing the memory (calloc())Allocating aligned memory blocks (memalign() and valloc())Storage allocation hooks (_malloc_hook, _realloc_ hook)Obstacks(stack like allocation,generally not so much used to malloc)AllocaReallocating allocator(GNU Extensions (r_alloc,r_alloc_free))Heap Consistency Checking(GNU Extensions(mcheck,mprobe))glibc: Supports All of the aboveBSD libc: Supports all except Storage allocation hooks ,obstacks,reallocating allocator, heap consistancy checking & valloc() is now obsolete with current malloc implementation which takes care for alignment on page size or larger allocations.6.Character Handling (tolower,toascii,etc)glibc: SupportedBSD libc: Supported.7.a)String and array utilitiesglibc: SupportedBSD libc:Supported except a few like strndup() and a few which are glibc specific like stpncpy,stpcpy are not Supported.b)Collation functions (strcoll,strxfrm)glibc: SupportedBSD libc: Supported.c)Search Functions (memchr,strchr)glibc: SupportedBSD libc: Supports except GNU extensions like memmem()8.a)Input/Output streams and Buffering:glibc: SupportedBSD libc: Supported.b)Line Oriented Inputglibc: SupportedBSD libc:Supported except GNU extensions like getline() and getdelim()c)Formatted Output(printf,sprintf,asprintf,etc)glibc: SupportedBSD libc: Supported except obstack_printf() and obstack_vprintf()d)Extend Syntax of printf template string (GNU extension)glibc: SupportedBSD libc: Not Supported.e)Other Streams(like string streams,Obstack streams,etc)glibc: SupportedBSD libc: Not Supported.
BSD supports funopen() which allows the user to create handles for
arbitrary stream types.

http://www.freebsd.org/cgi/man.cgi?query=funopen

glibc has fopencookie which is similar.

9.System call supportglibc: SupportedBSD libc: Supported.10.Support for Pipes and FIFOs.glibc: SupportedBSD libc: Supported.11.File System Interfaces glibc: SupportedBSD libc: Supported Except GNU extensions like getumask()12.Sockets Supportglibc: SupportedBSD libc: Supported.13.Terminal Interfaces (isatty,ttyname,etc).glibc: SupportedBSD libc: Supported.14.Math LibrarySupport for Mathematical computation and trignometric functions.glibc: SupportedBSD libc: Supported.15.Searching and sorting(eg:bsearch,qsort)glibc: SupportedBSD libc: Supported.16.Pattern matching(eg:fnmatch)glibc: SupportedBSD libc: Supported.17.Shell Style word expansion(Eg:wordexp,wordfree)glibc: SupportedBSD libc: Not Supported.
wordexp/wordfree are in 5.0, so they will probably be backported to 4.*
at some point.

18.Date and Timeglibc: SupportedBSD libc: Supported.19.Extended Charactersglibc: SupportedBSD libc: No multi-byte character set functions.Breaks building UTF(Unicode) support in libncurses.
wide character support is present in 5.0.

20.Locale and Internationalizationglibc: SupportedBSD libc:libintl and libiconv provides i18n support.By default libc does not contain ?lintl.21.Signal handlingglibc: SupportedBSD libc: Supported.22.Process startup and terminationProgram Arguments(Eg:getopt)Environment variablesProgram Terminationglibc: All SupportedBSD libc:Supported.(getopt_long updated from NetBSD)23.System database and name service switch(NSS)glibc: SupportedBSD libc: NSS not supported.Incompatible shadow and password support and ancient utmp.(Problem Solved by writing a library libshadow)
User applications should not need to know about FreeBSD's shadow
password style, so that shouldn't really matter.

5.0 has NSS.  Also, while it's obvious you're coming from a Linux
background, please note that it's equally valid to consider glibc as
the one with the incompatible password file format ;-).  What does
"ancient" mean, in technical terms?

24.User and Group Data baseglibc: SupportedBSD libc:Supported.Except a few functions like fgetpwent(),fgetpwent_r(),putpwent(),Fgetgrent(),fgetgrent_r(). 25.System Informationglibc: SupportedBSD libc: utsname() not Supported.
uname() is the correct function name (the data is returned in a struct
utsname), and BSD supports it.
26.System Configuration parametersglibc: SupportedBSD libc: Supported.27.Large file support(fseeko64,ftello64)glibc: SupportedBSD libc: Not Supported.
BSD has supported large files far longer than Linux has.  fseeko and
ftello are the functions you should use.  fseeko64 is sort of redundant :)

28.Debugging features (mtrace(memory leaks),backtrace,etc)glibc: SupportedBSD libc: Not Supported.29.glibc: Add-on packages CryptBSD libc:Contains additional libraries like Libcrypt


你可能感兴趣的:(character,extension,collation,alignment,Standards,Allocation)