Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Using open and other HAL unix standard functions

How do I use them? The HAL manual says to include <unistd.h> but this doesn&#39;t work. The example code says to include <stdio.h> but never mentions unistd.h. Neither of these work for me. I can&#39;t find where the alt_open.c declartion is declared in any header.

Why is the documentation so wrong? How do I use open.

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    OK the prototypes for the alt_open.c file are in alt_sys_wrappers.h

    But I have searched my entire harddrive for the flag definitions and found nothing (O_RDWR, WR_ONLY etc.). Also the example code uses open like you would fopen (with only 2 parameters).
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It seems my installation was corrupted and I was missing some library files. A reinstall seems to have fixed everything.

    However it does still appear to need <fctrl.h> included, even though the documentation doesn&#39;t specify this.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Whenever I come upon a question of what headers to include, I hop onto a computer with a "real" OS (i.e.: *not* Windows!) and view the manpage of the function in question. In this case the top part of the manpage for "open", returns:

    SYNOPSIS
          # include <sys/types.h>
          # include <sys/stat.h>
          # include <fcntl.h>
           int open(const char *pathname, int flags);
           int open(const char *pathname, int flags, mode_t mode);
           int creat(const char *pathname, mode_t mode);

    This tends to save me time and, since Windows documentation is a complete mess, it&#39;s much easier to find things on UNIX (or UNIX-like) OSs. If the documentation is wrong, it should certainly be updated, but I believe this little bit of info. to "common" knowledge... The two manpages I looked at (on Linux and Solaris) both had identical information.

    Cheers,

    - slacker