Newbie Question about #ifdef

D

Dale

I came across some code that had this in it:

#ifdef CYGWIN
ssize_t pread( int d, void *buf, size_t nbytes, off_t offset) {
lseek( d, offset, SEEK_SET );
read( d, buf, nbytes );
}
#endif

I wondered if the lseek and read methods (with these method
signatures) are standard, or would this code be looking for a dll?

I was thinking of trying to build this function in Java, but if it's
going to depend on a dll for which I do not have the source, that
would stop me in my tracks.

--Dale--
 
J

Jack Klein

I came across some code that had this in it:

#ifdef CYGWIN
ssize_t pread( int d, void *buf, size_t nbytes, off_t offset) {
lseek( d, offset, SEEK_SET );
read( d, buf, nbytes );
}
#endif

I wondered if the lseek and read methods (with these method
signatures) are standard, or would this code be looking for a dll?

I was thinking of trying to build this function in Java, but if it's
going to depend on a dll for which I do not have the source, that
would stop me in my tracks.

--Dale--

Neither lseek or read are part of the standard C library. They are
compiler/OS specific non-standard extensions. DLL's are not part or,
or defined by, the C language in any way, they are platform specific
mechanisms. You need to ask this question in a group that supports
your particular compiler/OS combination.
 
M

Martin Ambuhl

Dale said:
I came across some code that had this in it:

#ifdef CYGWIN
ssize_t pread( int d, void *buf, size_t nbytes, off_t offset) {
lseek( d, offset, SEEK_SET );
read( d, buf, nbytes );
}
#endif

I wondered if the lseek and read methods (with these method
signatures) are standard, or would this code be looking for a dll?

They are neither standard C nor are they necessarily in a shared
library. They are both standard POSIX, but that is off-topic here.
I was thinking of trying to build this function in Java, but if it's
going to depend on a dll for which I do not have the source, that
would stop me in my tracks.

The functionality of lseek() and read() should be obtainable with
(off-topic) Java-specific functions, just as it is with standard C
functions. If you can't figure out how to seek a position in a file and
read data from the file, you should be studying.
 
D

Dale

In case someone googles this and would like the result, here it is.

The #ifdef is a compiler directive; although lseek and read are not
available on Windows natively, they are available through this other
mechanism. After Jack's post, I looked around and found the
definition for the standard functionality for the two methods -
nothing magic in what they do and easily replicated in Java:

private byte[] pread (RandomAccessFile raf, int startLocation, int
numberOfBytes) throws Exception {
byte[] buf = new byte[numberOfBytes];
raf.seek(startLocation);
int numberRead = raf.read(buf,0,numberOfBytes);
return buf;
}
 
C

CBFalconer

Dale said:
In case someone googles this and would like the result, here it is.

The #ifdef is a compiler directive; although lseek and read are not
available on Windows natively, they are available through this other
mechanism. After Jack's post, I looked around and found the
definition for the standard functionality for the two methods -
nothing magic in what they do and easily replicated in Java:

private byte[] pread (RandomAccessFile raf, int startLocation, int
numberOfBytes) throws Exception {
byte[] buf = new byte[numberOfBytes];
raf.seek(startLocation);
int numberRead = raf.read(buf,0,numberOfBytes);
return buf;
}

Whatever you are talking about, don't top-post. Your response
belongs after, or intermixed with, the material to which you are
replying, with anything non-germand snipped out.

There are no such things as Java, lseek, read, private, pread,
throws, new, byte, raf.read, etc. etc. in ISO standard C, which is
the subject of this newsgroup, and is expected to be portable to
any system with a conforming C compiler.
 
J

John Bode

I came across some code that had this in it:

#ifdef CYGWIN
ssize_t pread( int d, void *buf, size_t nbytes, off_t offset) {
lseek( d, offset, SEEK_SET );
read( d, buf, nbytes );
}
#endif

I wondered if the lseek and read methods (with these method
signatures) are standard, or would this code be looking for a dll?

lseek and read are not part of the standard C library. They are
provided as part of the Cygwin environment. What the code above is
doing is checking to see if the symbol CYGWIN has been defined; if so,
the text between the #ifdef/#endif is compiled, otherwise it is
omitted. IOW, if we're compiling for the Cygwin environment, the
function pread() is defined as above.
I was thinking of trying to build this function in Java, but if it's
going to depend on a dll for which I do not have the source, that
would stop me in my tracks.

--Dale--

Java should already have equivalent functionality for lseek and read
as part of its standard class library, IINM. Unfortunately all my
Java references are somewhere else at the moment, so I could be wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top