LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-13-2013, 10:04 AM   #1
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Rep: Reputation: Disabled
POSIX Compliance


I'm trying to write a POSIX compliant application in C. I know that I can use the C standard runtime library, the POSIX C library, and the list of POSIX compliant utilities. I am wondering if there are any other libraries which are guaranteed POSIX compliant and how to get a list of them. For instance, I take it that I cannot use cURL for my internet communications, but will have to use POSIX sockets only. However, I would be interested in knowing whether there are libraries not specifically part of the POSIX standard which can be counted upon to be POSIX compliant.

Thanks.
 
Old 06-14-2013, 12:23 AM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
there is no list of libraries (as far as I know), but «system interfaces»: http://pubs.opengroup.org/onlinepubs...functions.html
(TOC: http://pubs.opengroup.org/onlinepubs/007904875/toc.htm)
 
Old 06-14-2013, 08:20 AM   #3
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
Thanks, but what about cURL, zLib (gzip), openssl, etc.? For all I know, some of these useful libraries may claim POSIX compliance. I was hoping that there could be some way to find out rather than a lot of Googling. It will be very hard to find out that a library is NOT POSIX compliant by random Googling. Anything that is not POSIX compliant I will be forced to re-implement myself, so I have a big motive to be able to identify libraries which do claim POSIX compliance.
 
Old 06-17-2013, 04:08 PM   #4
bloody
Member
 
Registered: Feb 2013
Location: Berlin
Distribution: Gentoo, Debian
Posts: 158

Rep: Reputation: 23
Those libs run well on POSIX-compatible systems, but POSIX does not include libs like zlib etc. because those are simply not part of the POSIX system definition. The links posted by Ygrex show you what POSIX is all about.

Expect libraries like curl, zlib, openssl etc. to be available on virtually any POSIX-compatible system, either in form of a distro package or at least easily installable by compiling the original sourcecode on that system. POSIX compatible basically means that Linux, *BSD (including Mac OS X), Solaris and a few others are on board. The only alien thing there is - as usual - Windows..
 
Old 06-17-2013, 04:45 PM   #5
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
It would just make my life easier if some of those libraries would declare themselves POSIX compliant. It would save me from having to re-implement the pieces of them that I need. I am under strict orders to produce an absolutely POSIX compliant program.
 
Old 06-17-2013, 06:06 PM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 11,447
Blog Entries: 4

Rep: Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505Reputation: 1505
Moderator Response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 06-17-2013, 09:44 PM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You also need to use the functions in a POSIX-compliant way (e.g. struct flock differs between Linux and FreeBSD,) and include the correct headers even if it compiles on your machine without doing so. You also need to keep in mind that some behaviors of POSIX and C functions only work on certain versions of libc (e.g. some of the GNU extensions for printf,) and certain system-call nuances will differ by operating system (e.g. you can put an advisory lock on a pipe on Linux but not on FreeBSD.)

Kevin Barry
 
Old 06-18-2013, 06:00 AM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by Brandon9000 View Post
It would just make my life easier if some of those libraries would declare themselves POSIX compliant. It would save me from having to re-implement the pieces of them that I need. I am under strict orders to produce an absolutely POSIX compliant program.
Why do you think you need to reimplement ? Simply make sure the libraries call only POSIX-compliant functions. If not, rewrite only the non-compliant parts - I think you'll hardly find any.

All those libraries compile under Linux/Solaris/*BSD/MacOS/Windows - which most likely means they are POSIX-compliant.
 
Old 06-18-2013, 09:17 AM   #9
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Sergei Steshenko View Post
Why do you think you need to reimplement ? Simply make sure the libraries call only POSIX-compliant functions. If not, rewrite only the non-compliant parts - I think you'll hardly find any.

All those libraries compile under Linux/Solaris/*BSD/MacOS/Windows - which most likely means they are POSIX-compliant.
How can I make sure that existing libraries call only POSIX compliant functions?

Also, "likely" isn't enough. In the cases where I've Googled some of these libraries, they haven't been claiming POSIX compliance. I'm afraid I cannot proceed with my current project based on a "probably." As for re-writing only the portions of a library which are not POSIX compliant, I agree that it's possible, but wouldn't it involve finding the source code and inspecting thousands of lines of (sometimes very opaque) code, and then re-doing and testing all non-compliant structures? Doing this for libxml2, zlib, libssl, etc., etc. seems almost as burdensome as re-creating the limited portions I need. I find it odd that there is no source that attempts to list which popular libraries are POSIX compliant.
 
Old 06-18-2013, 09:28 AM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by Brandon9000 View Post
How can I make sure that existing libraries call only POSIX compliant functions?
...

You build a library and then you run on it 'ldd' to see what other libraries it calls and 'nm' to see names in it, including function names.

You the determine which function belong to standard libraries and see their manpages to check whether they are compliant or not.

For example, 'man fopen' gives me the following prompt:

Code:
man fopen
Man: find all matching manual pages
 * fopen (3)
   fopen (3p)
Man: What manual page do you want?
- the 'p' in '3p' means 'POSIX'.

So you locate where 'fopen' is used and check whether it's used in POSIX-compliant way.

In the Linux version (i.e. '3' - not '3p') I see:

Code:
CONFORMING TO
       The fopen() and freopen() functions conform to C89.  The fdopen() function conforms to POSIX.1-1990.
.
 
Old 06-18-2013, 09:31 AM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by Brandon9000 View Post
...I find it odd that there is no source that attempts to list which popular libraries are POSIX compliant.

It is not odd - GNU autotools (you probably are familiar with 'configure' scripts) take care of this. Typically non-GUI stuff build equally well on all UNIX flavors.
 
Old 06-18-2013, 09:33 AM   #12
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
Wow, thanks! That is some great advice, together with excellent and clear explanations.

I still wish, though, that I didn't feel like the first person in history to do this in the sense that there is no list as to what is compliant, what is partially compliant, and what is non-compliant.
 
Old 06-18-2013, 10:03 AM   #13
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by Brandon9000 View Post
Wow, thanks! That is some great advice, together with excellent and clear explanations.

I still wish, though, that I didn't feel like the first person in history to do this in the sense that there is no list as to what is compliant, what is partially compliant, and what is non-compliant.
If you start reading Linux manpage, you'll find that sometimes POSIX non-compliance is intentional and for good reasons. E.g. POSIX compliance would cause ambiguity or buggy code.

A standard is not sacred. For example, there were numerous language defects found in C++ and filed against the standard.

...

My gut feeling tells me that *BSD as a more direct descendant of UNIX should be more POSIX-compliant; OTOH, I talked to a guy who worked with bot Linux and *BSD and at the time (2-3 years ago) and according to him Linux overall worked better. He was using file locking, multi-threading, etc.

Last edited by Sergei Steshenko; 06-18-2013 at 10:06 AM.
 
1 members found this post helpful.
Old 06-18-2013, 11:42 AM   #14
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
There isn't any point making sure your dependencies are written in a POSIX-compliant way, as long as you know they can be built for the OSes you target. Invariably libc and the dynamic linker won't be written in POSIX-compliant code, yet you'll almost always have them as dependencies. The point of writing your code in a POSIX-compliant way is so it will compile and execute properly on a variety of systems, but sometimes it's useful to take advantage of OS-specific functionality when it's available (using #ifdef blocks to specify alternate code.)

Kevin Barry
 
Old 06-18-2013, 01:40 PM   #15
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
For the present exercise, we're working on product which can be compiled and run on almost any Unixy system, both big and tiny. That's the goal.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PCI Compliance fetal Linux - Server 6 02-11-2013 10:55 PM
vsftpd and PCI compliance saraza Linux - Networking 3 09-22-2012 02:39 PM
of introduction and of first compliance thealmightyunicorn LinuxQuestions.org Member Intro 0 08-27-2012 05:44 PM
GPL Compliance jonnytabpni Linux - General 3 11-25-2009 12:30 AM
regarding POSIX compliance rajesh_b Programming 1 05-05-2006 04:31 AM


All times are GMT -5. The time now is 11:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration