home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / library / symlink.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  2KB  |  101 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  symlink.c,v 1.1.1.1 1994/04/04 04:30:36 amiga Exp
  20.  *
  21.  *  symlink.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:36  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.2  1992/07/04  19:21:58  mwild
  26.  *  cut a possibly leading `./' in symlink contents. This is a kludge, but it's
  27.  *  the only way to get `configure' working without changes.
  28.  *
  29.  * Revision 1.1  1992/05/14  19:55:40  mwild
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34. #define _KERNEL
  35. #include "ixemul.h"
  36. #include <string.h>
  37.  
  38. #ifndef LINK_SOFT
  39. #define LINK_SOFT 1
  40. #endif
  41.  
  42. static void u2a(const char *orig, char *new)
  43. {
  44.   if (index(orig, ':'))
  45.   {
  46.     strcpy(new, orig);
  47.     return;
  48.   }
  49.   if (*orig == '/')
  50.   {
  51.     while (*orig == '/')
  52.       orig++;
  53.     while (*orig && *orig != '/')
  54.       *new++ = *orig++;
  55.     *new++ = ':';
  56.     if (*orig)
  57.       orig++;
  58.   }
  59.   while (*orig)
  60.   {
  61.     if (!memcmp(orig, "../", 3))
  62.     {
  63.       orig += 3;
  64.       *new++ = '/';
  65.     }
  66.     else if (!memcmp(orig, "./", 2))     
  67.       orig += 2;
  68.     else if (*orig == '/')
  69.       orig++;
  70.     else if (!strcmp(orig, ".."))
  71.     {
  72.       orig += 2;
  73.       *new++ = '/';
  74.     }
  75.     else if (!strcmp(orig, "."))
  76.       orig++;
  77.     else
  78.     {
  79.       while (*orig && *orig != '/')
  80.         *new++ = *orig++;
  81.       if (*orig == '/')
  82.         *new++ = *orig++;
  83.     }
  84.   }
  85.   *new = '\0';
  86. }
  87.  
  88. int symlink (const char *old, const char *new)
  89. {
  90.   char *lstr;
  91.  
  92.   /* is long-alignment needed here? This is DOS, isn't it... */
  93.   lstr = alloca (strlen (old) + 4);
  94.   lstr = LONG_ALIGN (lstr);
  95.   u2a(old, lstr);
  96.   if (__make_link ((char *)new, (BPTR)lstr, LINK_SOFT))
  97.     return 0;
  98.   errno = __ioerr_to_errno(IoErr());
  99.   return -1;
  100. }
  101.