NO

Author Topic: how to use the c functions in unix  (Read 2362 times)

liut

  • Guest
how to use the c functions in unix
« on: April 05, 2012, 07:28:43 AM »
Hello, I'm using PellesC 6.0 and want to compile some codes with many traditional unix-style c functions. I can see the .h files in the dir 'include', such as io.h / fcntl.h ... but when I build the project, the ide always show me warnings and errors regarding 'missing prototype for those functions' or 'undeclared identifier'. Here is the simple test code:

#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>

char *filename="mytext.txt";
char *text="Hello, world!\n";

int main()
{
   int i;

   i=open(filename,O_CREAT|O_RDWR);
   if(i==-1){
      printf("error to open the file!\n");
      return -1;
   }

   if(write(i,text,strlen(text))==-1){
      printf("fail to write!\n");
      close(i);
      return -1;
   }
   else{
      printf("success to write!\n");
      close(i);
      return 0;
   }
}

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2114
Re: how to use the c functions in unix
« Reply #1 on: April 05, 2012, 09:18:58 AM »
The original definitions for many old times functions (as open and its flags) are considered deprecated and renamed prepending an underscore. Anyway you can force compiler to define them in original form (without underscore) by using the switch "-Go" on the compiler command line, or checking it on the project compiler tab if you use the IDE.
So you have two options set oldnames by switch, or prepend an undescore to them.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

liut

  • Guest
Re: how to use the c functions in unix
« Reply #2 on: April 05, 2012, 11:56:07 AM »
thanks a lot! It works.    :)