/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that prints the file linked with
a referred file. */
#include <stdio.h>
#include <unistd.h>
#define SIZE 80

int main() {
    char buf[SIZE];
    char *name1, *name2;
  
    if((name1 = tmpnam(NULL)) == NULL) {
        printf("Error in creating temp file.\n");
        exit(1);
    }
    if((name2 = tmpnam(NULL)) == NULL) {
        printf("Error in creating temp file.\n");
        exit(1);
    }
    unlink(name2);
    if(symlink(name1,name2) != 0) {
        perror("cannot create symbolic link\n");
        exit(1);
    }
    if((readlink(name2,buf,SIZE)) != -1) 
        printf("The file linked with '%s' is '%s'\n",name2,buf);
    else
	printf("Error!\n");
}
