Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Strange "read" and "write" functions in OIS


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 TheComet   Crossbones+   -  Reputation: 1622

Like
0Likes
Like

Posted 17 May 2014 - 06:19 PM

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?

 


YOUR_OPINION >/dev/null

Sponsor:

#2 bradbobak   Members   -  Reputation: 1133

Like
3Likes
Like

Posted 17 May 2014 - 06:45 PM

 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.



#3 TheComet   Crossbones+   -  Reputation: 1622

Like
0Likes
Like

Posted 18 May 2014 - 04:31 AM

Yes that fixed it, thanks!


YOUR_OPINION >/dev/null

#4 Ectara   Crossbones+   -  Reputation: 3019

Like
0Likes
Like

Posted 18 May 2014 - 05:50 PM


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.



#5 Jan2go   Members   -  Reputation: 895

Like
0Likes
Like

Posted 19 May 2014 - 01:53 AM

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.



#6 bradbobak   Members   -  Reputation: 1133

Like
0Likes
Like

Posted 19 May 2014 - 01:45 PM

 


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.



#7 Ectara   Crossbones+   -  Reputation: 3019

Like
0Likes
Like

Posted 21 May 2014 - 08:09 PM


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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS