Sun Studio 12: Fortran Library Reference

1.4.31 link, symlnk: Make a Link to an Existing File

link creates a link to an existing file. symlink creates a symbolic link to an existing file.

The functions are called by:

status = link( name1, name2 )

INTEGER*4 symlnk

status = symlnk( name1, name2 )

name1

character*n

Input 

Path name of an existing file 

name2

character*n

Input 

Path name to be linked to the file, name1.

name2 must not already exist.

Return value 

INTEGER*4

Output 

status=0: OK

status>0: System error code

1.4.31.1 link: Create a Link to an Existing File

Example 1: link: Create a link named data1 to the file, tlink.db.data.1:


demo% cat tlink.f
        character*34 name1/’tlink.db.data.1’/, name2/’data1’/
        integer*4 link, status
        status = link( name1, name2 )
        if ( status .ne. 0 ) stop ’link: error’
        end
demo% f95 tlink.f
demo% ls -l data1
data1 not found
demo% a.out
demo% ls -l data1
-rw-rw-r-- 2 generic 2 Aug 11 08:50 data1
demo%

1.4.31.2 symlnk: Create a Symbolic Link to an Existing File

Example 2: symlnk: Create a symbolic link named data1 to the file, tlink.db.data.1:


demo% cat tsymlnk.f
       character*34 name1/’tlink.db.data.1’/, name2/’data1’/
       INTEGER*4 status, symlnk
       status = symlnk( name1, name2 )
       if ( status .ne. 0 ) stop ’symlnk: error’
       end
demo% f95 tsymlnk.f
demo% ls -l data1
data1 not found
demo% a.out
demo% ls -l data1
lrwxrwxrwx 1 generic 15 Aug 11 11:09 data1 -> tlink.db.data.1
demo%

See also: link(2), symlink(2), perror(3F), and unlink(3F).

Note: the path names cannot be longer than MAXPATHLEN as defined in <sys/param.h>.