home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / readlink.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  3.1 KB  |  155 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.2;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.2
  10. date    92.05.18.12.22.32;    author mwild;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.05.14.19.55.40;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @read symbolic link
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @set errno, and only send READLINK packet if the file really is a symlink
  28. @
  29. text
  30. @/*
  31.  *  This file is part of ixemul.library for the Amiga.
  32.  *  Copyright (C) 1991, 1992  Markus M. Wild
  33.  *
  34.  *  This library is free software; you can redistribute it and/or
  35.  *  modify it under the terms of the GNU Library General Public
  36.  *  License as published by the Free Software Foundation; either
  37.  *  version 2 of the License, or (at your option) any later version.
  38.  *
  39.  *  This library is distributed in the hope that it will be useful,
  40.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  41.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  42.  *  Library General Public License for more details.
  43.  *
  44.  *  You should have received a copy of the GNU Library General Public
  45.  *  License along with this library; if not, write to the Free
  46.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47.  *
  48.  *  $Id: readlink.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  49.  *
  50.  *  $Log: readlink.c,v $
  51.  * Revision 1.1  1992/05/14  19:55:40  mwild
  52.  * Initial revision
  53.  *
  54.  */
  55.  
  56. #define KERNEL
  57. #include "ixemul.h"
  58.  
  59. #if __GNUC__ != 2
  60. #define alloca __builtin_alloca
  61. #endif
  62.  
  63. #ifndef ERROR_IS_SOFT_LINK
  64. #define ERROR_IS_SOFT_LINK  233
  65. #endif
  66.  
  67. #ifndef ACTION_READ_LINK
  68. #define ACTION_READ_LINK 1024
  69. #endif
  70.  
  71. struct readlink_vec {
  72.   char *buf;
  73.   int bufsize;
  74. };
  75.  
  76. static int
  77. __readlink_func (struct StandardPacket *sp, struct MsgPort *handler,
  78.                  BPTR parent_lock,
  79.              BSTR name,
  80.              struct readlink_vec *rv, int *no_error)
  81. {
  82.   /* this baby uses CSTRings, absolutely unique... */
  83.   unsigned char *np = BTOCPTR (name);
  84.   np[*np + 1] = 0; np++;
  85.  
  86.   sp->sp_Pkt.dp_Type = ACTION_READ_LINK;
  87.   sp->sp_Pkt.dp_Arg1 = parent_lock;
  88.   sp->sp_Pkt.dp_Arg2 = (long) np;
  89.   sp->sp_Pkt.dp_Arg3 = (long) rv->buf;
  90.   sp->sp_Pkt.dp_Arg4 = rv->bufsize;
  91.  
  92.   PutPacket (handler, sp);
  93.   __wait_sync_packet (sp);
  94.  
  95.   *no_error = sp->sp_Pkt.dp_Res1 > 0;
  96.  
  97.   /* this *can't* be a symlink... */
  98.   return 0;
  99. }
  100.  
  101. int 
  102. readlink(char *path, char *buf, int bufsiz)
  103. {
  104.   struct readlink_vec rv;
  105.   struct stat stb;
  106.   int rc;
  107.   
  108.   /* readlink is buggy in the current fs release (37.26 here), in that
  109.      it reports OBJECT_NOT_FOUND if a file is present but not a 
  110.      symbolic link */
  111.   if (lstat (path, &stb) == 0)
  112.     {
  113.       if (S_ISLNK (stb.st_mode))
  114.     {
  115.       rv.buf = buf;
  116.       rv.bufsize = bufsiz;
  117.   
  118.       rc = __plock (path, __readlink_func, &rv);
  119.       if (rc <= 0)
  120.         errno = __ioerr_to_errno (IoErr ());
  121.       return rc > 0 ? rc : -1;
  122.     }
  123.       else
  124.     errno = EINVAL;
  125.     }
  126.   /* errno should be set already by lstat() */
  127.   return -1;
  128. }
  129. @
  130.  
  131.  
  132. 1.1
  133. log
  134. @Initial revision
  135. @
  136. text
  137. @d19 1
  138. a19 1
  139.  *  $Id$
  140. d21 4
  141. a24 1
  142.  *  $Log$
  143. d76 1
  144. d79 9
  145. a87 2
  146.   rv.buf = buf;
  147.   rv.bufsize = bufsiz;
  148. d89 10
  149. a98 4
  150.   rc = __plock (path, __readlink_func, &rv);
  151.   if (rc <= 0)
  152.     errno = __ioerr_to_errno (IoErr ());
  153.   return rc > 0 ? rc : -1;
  154. @
  155.