Compilation problem with semtimedop

Hi,

I'm porting code from Windows to HP-UX 11, compiling with gcc.
I have a call to semtimedop with 4 arguments as in the definition:

int semtimedop(int, struct sembuf *, unsigned int, const struct timespec *);

When compiling I get an error saying:
error: 'semtimedop' was not declared in this scope

I looked in /usr/include/sys/sem.h to see what compilation flags are needed, and it seems to me that there is an anomally there. In the excerpt from sem.h at the bootom, I have left the ifdefs and removed the code between them (faithfully, I hope) until the definition of semtimedop. As I understand it, it is impossible to reach the correct definition of semtimedop with arguments, since on the one hand it is under a global

#ifdef _INCLUDE_XOPEN_SOURCE

but on the other hand within this global ifdef it is under the else: of:

if defined(_INCLUDE_XOPEN_SOURCE) || defined(__LP64__)

This leaves me only with the definition of semtimedop as:

     extern int semtimedop();

which does not please the compiler.

Am I wrong? What is the correct way to solve this?

Thank you,

Rimon

Edited excerpt from sem.h:

#ifdef _INCLUDE_XOPEN_SOURCE


#  ifndef _NO_USER_PROTOS


#  ifdef _PROTOTYPES

#   if defined(_INCLUDE_XOPEN_SOURCE) || defined(__LP64__)
     extern int semop(int, struct sembuf *, size_t);
#   else /* not XOPEN_SOURCE or LP64 */
     extern int semop(int, struct sembuf *, unsigned int);
#    ifdef _INCLUDE_HPUX_SOURCE
      extern int semtimedop(int, struct sembuf *, unsigned int, const struct timespec *);
#    endif /* _INCLUDE_HPUX_SOURCE */
#   endif /* not XOPEN_SOURCE or LP64 */
#  else /* not _PROTOTYPES */
     extern int semctl();
     extern int semget();
     extern int semop();
#    ifdef _INCLUDE_HPUX_SOURCE
      extern int semtimedop();
#    endif /* _INCLUDE_HPUX_SOURCE */
#  endif /* not _PROTOTYPES */

#  ifdef __cplusplus
     }
#  endif /* __cplusplus */
#  endif /* not _NO_USER_PROTOS */
#endif /* _INCLUDE_XOPEN_SOURCE */






What code are you porting? I do the following mapping:

Win32 Event -> pthread_cond_t

Win32 Mutex -> pthread_mutex_t

On HPUX, I use

-D_XOPEN_SOURCE_EXTENDED -D_REENTRANT

The relevant portion of the code I am porting manages semphores between the threads in my application. The specific call which gives me the compliation error is:

               rc = semtimedop(*sem_idp, sops, nsops, t_spec);

I tried the flags you mention but I'm afraid they don't solve the problem - I still get the compilation error.

I recommend you use a pthread construct to do what you want to do, or build a semaphore using a pthread condition.