473,834 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C runtime library for Unix

I would like to port PDPCLIB:

http://sourceforge.net/projects/pdos/

my public domain C runtime library for DOS, OS/2,
Win32, MVS to Unix now.

I am a bit perplexed as to how to do this. Unix/Posix
systems provide open() with which I can implement
fopen(). But then Posix is also required to define fopen(),
so this is not the level at which I need to implement it.

Although I don't think the CRT should be polluting the
namespace by using open() in the first place.

If the lower level is platform-dependent, then the platform
I wish to target is Linux.

Can someone get me started?

Thanks. Paul.
Nov 17 '06 #1
21 3090
Paul Edwards wrote:
I would like to port PDPCLIB:

http://sourceforge.net/projects/pdos/

my public domain C runtime library for DOS, OS/2,
Win32, MVS to Unix now.

I am a bit perplexed as to how to do this. Unix/Posix
systems provide open() with which I can implement
fopen(). But then Posix is also required to define fopen(),
so this is not the level at which I need to implement it.

Although I don't think the CRT should be polluting the
namespace by using open() in the first place.

If the lower level is platform-dependent, then the platform
I wish to target is Linux.

Can someone get me started?
As a system library, you'll need to only rely on the APIs exported by
the OS. Linux aims towards POSIX compliance and thus implements many
APIs defined by POSIX. The system C library often also provides POSIX
interface.

In general you should try to do as much as possible within standard C
and write specific functions when they're called for. If you want the
library to port to most UNIXes, it's structure and compilation will get
more involved. If it's specifically for Linux, then it'll be much
simpler.

At a minimum you'll need to refer to the C standard, the POSIX
standards and the man 2 pages for the OS API. The tricky part will be
satisfying the OS without sacrificing too much portability.

Post Linux API related questions to one of the Linux groups. Details
within standard C portions can be discussed here or in comp.std.c, (but
I doubt that those areas would be much of a problem for you).

The Linux newsgroups will probably help you best. Also browse the
sources of C libraries like dietlibc etc.

Nov 17 '06 #2
"santosh" <sa*********@gm ail.comwrote in message news:11******** **************@ e3g2000cwe.goog legroups.com...
Also browse the sources of C libraries like dietlibc etc.
Thanks. I found that, and their fopen() calls __libc_open()
which in turn calls __syscall_open( ).

The __syscall_open( ) is presumably what the OS exports,
and what I need to use to avoid polluting the user's namespace
by a direct call to open().

I haven't found where __syscall_open( ) is defined yet,
but I found a sys_open() in syscalls.h. Maybe that's the
proper one to use.

BFN. Paul.
Nov 17 '06 #3
Paul Edwards skrev:

[...]
I haven't found where __syscall_open( ) is defined yet,
but I found a sys_open() in syscalls.h. Maybe
that's the proper one to use.
sys_open()
sys_read()
sys_write()
sys_close()

BUT, why not look up the Linux kernel documentation or
ask in a forum where Linux is on-topic?

comp.os.linux.m isc
comp.os.linux.d evelopment.syst em
comp.os.linux.d evelopment.apps
etc.

<gd&r>

--
Tor <torust AT online DOT no>

Nov 17 '06 #4


Paul Edwards wrote On 11/17/06 15:20,:
"santosh" <sa*********@gm ail.comwrote in message news:11******** **************@ e3g2000cwe.goog legroups.com...
>>Also browse the sources of C libraries like dietlibc etc.


Thanks. I found that, and their fopen() calls __libc_open()
which in turn calls __syscall_open( ).

The __syscall_open( ) is presumably what the OS exports,
and what I need to use to avoid polluting the user's namespace
by a direct call to open().

I haven't found where __syscall_open( ) is defined yet,
but I found a sys_open() in syscalls.h. Maybe that's the
proper one to use.
Why is it better to pollute the user's namespace
with sys_open() than with open()?

--
Er*********@sun .com

Nov 17 '06 #5
Paul Edwards wrote:
"santosh" <sa*********@gm ail.comwrote in message news:11******** **************@ e3g2000cwe.goog legroups.com...
Also browse the sources of C libraries like dietlibc etc.

Thanks. I found that, and their fopen() calls __libc_open()
which in turn calls __syscall_open( ).

The __syscall_open( ) is presumably what the OS exports,
and what I need to use to avoid polluting the user's namespace
by a direct call to open().

I haven't found where __syscall_open( ) is defined yet,
but I found a sys_open() in syscalls.h. Maybe that's the
proper one to use.
No. This is still a feature of the existing C library. If you want your
CRT to be independant of other libraries, you must directly call the
kernel by means of assembler, (either INT, SYSCALL, SYSENTER etc). The
API exported by the kernel is available in the 'asm/unistd.h' header
for UNIX like kernels. For each defined syscall, refer to it's man 2
page for the official documentation, but they're often not good enough
to enable you to write robust code, (especially for newer system
calls). As the ultimate reference, the kernel's source may have to
consulted.

To enable the rest of your library to be portable, you'll probably want
to create wrappers around system calls, just like existing sys_open()
sys_write() etc.

Nov 18 '06 #6
"Eric Sosman" <Er*********@su n.comwrote in message news:1163805399 .935710@news1nw k...
The __syscall_open( ) is presumably what the OS exports,
and what I need to use to avoid polluting the user's namespace
by a direct call to open().

I haven't found where __syscall_open( ) is defined yet,
but I found a sys_open() in syscalls.h. Maybe that's the
proper one to use.

Why is it better to pollute the user's namespace
with sys_open() than with open()?
Technically it isn't, but since no-one actually uses sys_open(),
I didn't think anyone would notice.

I have the same problem with Win32. It is polluting the user's
namespace with CreateFile(). I don't know how to get around
that. I wonder what other C compilers do?

BFN. Paul.
Nov 18 '06 #7
Paul Edwards said:
"Eric Sosman" <Er*********@su n.comwrote in message
news:1163805399 .935710@news1nw k...
>>
Why is it better to pollute the user's namespace
with sys_open() than with open()?

Technically it isn't, but since no-one actually uses sys_open(),
I didn't think anyone would notice.

I have the same problem with Win32. It is polluting the user's
namespace with CreateFile(). I don't know how to get around
that. I wonder what other C compilers do?
Don't worry about it. Since no-one actually uses CreateFile() - except as a
Win32 API call - I don't think anyone will notice.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 18 '06 #8
Eric Sosman skrev:
Paul Edwards wrote On 11/17/06 15:20,:
[...]
The __syscall_open( ) is presumably what the OS exports,
and what I need to use to avoid polluting the user's namespace
by a direct call to open().

Why is it better to pollute the user's namespace
with sys_open() than with open()?
I don't get it. Why does the standard library pollute user's
namespace?

Internally, the library will have e.g. <open.c>, which calls the
OS functions. So those OS calls shouldn't be visable to the
library caller... so is it a link problem we talk about here?

--
Tor <torust AT online DOT no>

Nov 18 '06 #9
"Tor Rustad" <to********@hot mail.comwrote in message news:11******** *************@m 73g2000cwd.goog legroups.com...
Eric Sosman skrev:
Paul Edwards wrote On 11/17/06 15:20,:

[...]
The __syscall_open( ) is presumably what the OS exports,
and what I need to use to avoid polluting the user's namespace
by a direct call to open().
Why is it better to pollute the user's namespace
with sys_open() than with open()?

I don't get it. Why does the standard library pollute user's
namespace?

Internally, the library will have e.g. <open.c>, which calls the
OS functions. So those OS calls shouldn't be visable to the
library caller... so is it a link problem we talk about here?
Yes, the problem will occur at link time. The C library is
not meant to be dependent on functions which are in the
user's namespace. The C library is allowed to use names
such as __open() or _Open() (on a case-sensitive system),
but not open().

BFN. Paul.
Nov 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
40506
by: JW | last post by:
Hi, I don't seem to get any results from the following use of Runtime.getRuntime().exec(cmd) using Java 1.4 on Redhat linux. Suppose that in the same directory as my java file below, I have files junk1, junk2, junk3, and i want to have the java program delete all of these files.
3
4273
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is active? Can the setting of LD_LIBRARY_PATH guanrantee that the correct one is executed? 2> In MS-WINDOWS, once a DLL is loaded by one allication, this DLL will be used by the subsequent appication. Does UNIX have the same
5
3549
by: markus | last post by:
Hi, I have a question that deals with the standard c library VS (Unix) system calls. The question is: which header files (and functions) are part of the C library and which header files (and function calls) are part of the (Unix) system calls. The cause of my confusion is that for example stdio.h is considered
7
7640
by: marek | last post by:
Dear colleagues, for one project, I need to link Turbo (or Borland) Pascal with (Turbo) C code. I would strongly like to avoid rewriting (my) C routines to Pascal (other part of project is under Unix [yes, I know about gpc and fpc...), and my clients are medicine doctors, who reject to program in other lang. than Pascal. Linking of Turbo C 2 and TP 5.5 from Borland's "Antique software" works, but there is a well-known problem with...
6
1584
by: ritesh | last post by:
Hi, I have been reading some text on C and C++ (i.e advanced books). One of the books mentioned that C++ requires a runtime support whereas C does not - what the author was trying to say was that once you compile a C program the executable created is all that is needed whereas if you compile a C++ program the executable created requires a C++ runtime installed on your system to run the program. Can someone please provide more...
36
3665
by: lovecreatesbeauty | last post by:
In the C programming language, I/O operation functions are declared in stdio.h, for example, fopen(), fclose(), fwrite(), fread(), fseek() ... But another set of I/O functions are also defined in Unix, for example, open(), close(), read(), write(), lseek() ... Which set of functions is more suitable for I/O task, C library version or Unix version? Thank you
18
4366
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters, isn't easy. As far as I can see, there are only two solutions: 1) This one is portable. If...
2
2811
by: sealo | last post by:
Hello, How does the C# App search the library in the runtime? Say, I build a C# App A, which use B.dll, and B.dll use the C.dll. I specify the B.dll and C.dll path in the IDE, and build was passed. If I run the app, do I need to put the B.dll and C.dll in the same directory with the App? How does the app search the library which he need? Or, is there some environment variable of Library Path in .NET, like "LD_LIBRARY_PATH" in UNIX?
20
3545
by: J de Boyne Pollard | last post by:
MThe library functions which are included to allow process Mlaunch, forking, and termination, imply that it is both Mpossible and desirable for a process to fork itself. This is Ma fundamental part of the Unix thought process, but is Mnot essential for a working OS. There are no Standard C Library functions for process forking or overlaying. The fork() and execve() functions are part of the C language bindings to POSIX. They are not...
0
9800
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10557
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10225
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9340
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5630
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5802
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3987
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.