Thread: Headers for IPC require manual inclusion of prototypes?!?

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    30

    Headers for IPC require manual inclusion of prototypes?!?

    I'm writing a program/function that can takeover control of any program through IPC pipes. The program is working fine, but I don't understand something...

    On all previous programs I have written, I've never had to declare a function prototype for a function contained in a header (ie. never declared printf function prototype when I use it).

    But for IPC, you need four special functions (along with others):
    Code:
    posix_openpt()
    grantpt()
    unlockpt()
    ptsname()
    From reading the man pages, the only headers I need are:
    Code:
    stdlib.h
    fcntl.h
    For some reason, without adding those function prototypes to my program, I get the following errors:
    Code:
    takeover_program.c: In function 'takeover_program':
    takeover_program.c:50:12: error: implicit declaration of function 'posix_openpt' [-Werror=implicit-function-declaration]
      if((fdm = posix_openpt(O_RDWR)) == -1)
                ^~~~~~~~~~~~
    takeover_program.c:56:5: error: implicit declaration of function 'grantpt' [-Werror=implicit-function-declaration]
      if(grantpt(fdm) == -1)
         ^~~~~~~
    takeover_program.c:63:5: error: implicit declaration of function 'unlockpt' [-Werror=implicit-function-declaration]
      if(unlockpt(fdm) == -1)
         ^~~~~~~~
    takeover_program.c:70:19: error: implicit declaration of function 'ptsname' [-Werror=implicit-function-declaration]
      if((slave_name = ptsname(fdm)) == NULL)
                       ^~~~~~~
    So my question is why aren't these prototypes included in the header files? I assume I'm correct in what I'm doing, as the program compiles without errors and executes properly.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    Read the man page more carefully. Note that it says you need _XOPEN_SOURCE >= 600. So you need to define that symbol with (at least) that value before including the headers.

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    30
    Quote Originally Posted by john.c View Post
    Read the man page more carefully. Note that it says you need _XOPEN_SOURCE >= 600. So you need to define that symbol with (at least) that value before including the headers.
    I was under the impression that some functions can be implemented as macros instead. I thought that's why they list it as a 'Feature Test Macro'.

    But after reading 'man 7 feature_test_macro' I feel I have a better understanding. Ty.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-07-2014, 09:36 PM
  2. Require help decrypting XOR.
    By mkthnx001 in forum C++ Programming
    Replies: 15
    Last Post: 05-17-2009, 07:15 PM
  3. including headers inside headers
    By kromozom in forum C++ Programming
    Replies: 5
    Last Post: 04-18-2005, 10:56 AM
  4. Require information!!!!
    By sameer in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2002, 06:51 AM

Tags for this Thread