mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-08-26 10:58:49 +08:00
* include/rtems/libio_.h: Remove set_errno_and_return_minus_one. * libc/cfsetispeed.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/cfsetospeed.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/chdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/chmod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/chown.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/chroot.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/closedir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/eval.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/fchdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/fchmod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/fdatasync.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/fpathconf.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/fstat.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/fsync.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/ftruncate.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/getdents.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/ioctl.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/link.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/lseek.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/mknod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/open.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/read.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/readlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/rmdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/stat.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/symlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/tcsetattr.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/telldir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/ttyname.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/ttyname_r.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/unlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/unmount.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/utime.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one. * libc/write.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
106 lines
2.3 KiB
C
106 lines
2.3 KiB
C
/*
|
|
* link() - POSIX 1003.1b - 5.3.4 - Create a new link
|
|
*
|
|
* COPYRIGHT (c) 1989-1999.
|
|
* On-Line Applications Research Corporation (OAR).
|
|
*
|
|
* The license and distribution terms for this file may be
|
|
* found in the file LICENSE in this distribution or at
|
|
* http://www.OARcorp.com/rtems/license.html.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
#if HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <rtems.h>
|
|
#include <rtems/libio.h>
|
|
#include <errno.h>
|
|
|
|
#include <rtems/libio_.h>
|
|
#include <rtems/seterr.h>
|
|
|
|
int link(
|
|
const char *existing,
|
|
const char *new
|
|
)
|
|
{
|
|
rtems_filesystem_location_info_t existing_loc;
|
|
rtems_filesystem_location_info_t parent_loc;
|
|
int i;
|
|
int result;
|
|
const char *name_start;
|
|
|
|
/*
|
|
* Get the node we are linking to.
|
|
*/
|
|
|
|
result = rtems_filesystem_evaluate_path( existing, 0, &existing_loc, TRUE );
|
|
if ( result != 0 )
|
|
return -1;
|
|
|
|
/*
|
|
* Get the parent of the node we are creating.
|
|
*/
|
|
|
|
rtems_filesystem_get_start_loc( new, &i, &parent_loc );
|
|
|
|
if ( !parent_loc.ops->evalformake_h ) {
|
|
rtems_filesystem_freenode( &existing_loc );
|
|
rtems_set_errno_and_return_minus_one( ENOTSUP );
|
|
}
|
|
|
|
result = (*parent_loc.ops->evalformake_h)( &new[i], &parent_loc, &name_start );
|
|
if ( result != 0 ) {
|
|
rtems_filesystem_freenode( &existing_loc );
|
|
rtems_set_errno_and_return_minus_one( result );
|
|
}
|
|
|
|
/*
|
|
* Check to see if the caller is trying to link across file system
|
|
* boundaries.
|
|
*/
|
|
|
|
if ( parent_loc.mt_entry != existing_loc.mt_entry ) {
|
|
rtems_filesystem_freenode( &existing_loc );
|
|
rtems_filesystem_freenode( &parent_loc );
|
|
rtems_set_errno_and_return_minus_one( EXDEV );
|
|
}
|
|
|
|
if ( !parent_loc.ops->link_h ) {
|
|
rtems_filesystem_freenode( &existing_loc );
|
|
rtems_filesystem_freenode( &parent_loc );
|
|
rtems_set_errno_and_return_minus_one( ENOTSUP );
|
|
}
|
|
|
|
result = (*parent_loc.ops->link_h)( &existing_loc, &parent_loc, name_start );
|
|
|
|
rtems_filesystem_freenode( &existing_loc );
|
|
rtems_filesystem_freenode( &parent_loc );
|
|
|
|
return result;
|
|
}
|
|
|
|
/*
|
|
* _link_r
|
|
*
|
|
* This is the Newlib dependent reentrant version of link().
|
|
*/
|
|
|
|
#if defined(RTEMS_NEWLIB)
|
|
|
|
#include <reent.h>
|
|
|
|
int _link_r(
|
|
struct _reent *ptr,
|
|
const char *existing,
|
|
const char *new
|
|
)
|
|
{
|
|
return link( existing, new );
|
|
}
|
|
#endif
|
|
|