/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that associates a stream
with a file descriptor. */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main() {
    int fildes;
    FILE *fp;
    
    /* open file for reading only */
    if((fildes = open("fdopen.c",O_RDONLY)) == -1){ 
        printf("cannot open file");
        exit(1);
    }
    fp = fdopen(fildes,"r");
    if(fp==NULL) {
       printf("error in fdopen().\n");
    }
    else {
       if(fclose(fp)) 
          printf("error in closing file\n");
       else
          printf("Successfully opened.\n");
    }
}
