Strange "read" and "write" functions in OIS

Started by
5 comments, last by Ectara 9 years, 11 months ago

So I decided to build OIS 1.3 from source, and can't figure out why it's not compiling.

http://sourceforge.net/projects/wgois/

I did the usual procedure with:


./bootstrap
./configure
make

And get the following error:


libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../includes -I../includes -g -O2 -I/usr/X11R6/include -I/home/alex/Documents/c++/dep/include -g -O2 -MT LinuxJoyStickEvents.lo -MD -MP -MF .deps/LinuxJoyStickEvents.Tpo -c ./linux/LinuxJoyStickEvents.cpp  -fPIC -DPIC -o .libs/LinuxJoyStickEvents.o
./linux/LinuxJoyStickEvents.cpp: In member function 'virtual void OIS::LinuxJoyStick::capture()':
./linux/LinuxJoyStickEvents.cpp:100:77: error: 'read' was not declared in this scope
   int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
                                                                             ^
./linux/LinuxJoyStickEvents.cpp: In static member function 'static OIS::JoyStickInfoList OIS::LinuxJoyStick::_scanJoys()':
./linux/LinuxJoyStickEvents.cpp:275:13: error: 'close' was not declared in this scope
     close(fd);
             ^
./linux/LinuxJoyStickEvents.cpp:283:12: error: 'close' was not declared in this scope
    close(fd);
            ^
./linux/LinuxJoyStickEvents.cpp: In static member function 'static void OIS::LinuxJoyStick::_clearJoys(OIS::JoyStickInfoList&)':
./linux/LinuxJoyStickEvents.cpp:294:20: error: 'close' was not declared in this scope
   close(i->joyFileD);
                    ^
make[1]: *** [LinuxJoyStickEvents.lo] Error 1
make[1]: Leaving directory `/home/alex/Documents/c++/packages/ois-v1-3/src'
make: *** [all-recursive] Error 1

The code in question is here:


        //We are in non blocking mode - we just read once, and try to fill up buffer
        input_event js[JOY_BUFFERSIZE];
        while(true)
        {
                int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
        if( ret < 0 )
                        break;

What on earth is this "read" function and where did it come from? There are counterpart "write" functions with the same signatures, and I don't have the faintest idea of where they even come from...

Any help?

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty
Advertisement

read, write, and close are posix functions. 'man 2 read' in unix should bring up the man pages.

From your compiler output it seems like the header files are not being included. Try including <unistd.h>, that may fix your problem.

Yes that fixed it, thanks!

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty


The code in question is here:

//We are in non blocking mode - we just read once, and try to fill up buffer
input_event js[JOY_BUFFERSIZE];
while(true)
{
int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
if( ret < 0 )
break;

It may just be me, but that looks like a buffer overflow.

You can also get OIS 1.4 is available on GitHub (download the master branch). When I added OIS into my code about half a year ago I had to use this version as I had some problems (not related to the one you had) with 1.3.


The code in question is here:

//We are in non blocking mode - we just read once, and try to fill up buffer
input_event js[JOY_BUFFERSIZE];
while(true)
{
int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
if( ret < 0 )
break;

It may just be me, but that looks like a buffer overflow.

Don't think so. read reads bytes and the array size is specified correctly.


Don't think so. read reads bytes and the array size is specified correctly.

http://bytes.com/topic/c/answers/616647-why-address-array-equals-array

Huh, no way. The same address, but different type for using js vs. &js in an expression. I've never tried, because it seemed counter-intuitive to try to take the address of an array that decays to a pointer that I wanted in the first place.

This topic is closed to new replies.

Advertisement