home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / symlink.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  1KB  |  62 lines

  1. /* soft link routines */
  2.  
  3. #include <mintbind.h>
  4. #include <errno.h>
  5. #include <string.h>
  6. #include <limits.h>
  7. #include "lib.h"
  8.  
  9. extern int __mint;
  10.  
  11. /*
  12.  * If MiNT 0.9 or later is active, use the kernel routines for these;
  13.  * otherwise, try to choose failure modes that applications will best be
  14.  * able to handle
  15.  */
  16.  
  17. int
  18. symlink(old, new)
  19.     char *old, *new;
  20. {
  21.     char linkname[PATH_MAX];
  22.     char path[PATH_MAX];
  23.     long r;
  24.  
  25.     if (__mint >= 9) {
  26.         _unx2dos(old, path);
  27.         _unx2dos(new, linkname);
  28.         r = Fsymlink(path, linkname);
  29.         if (r) {
  30.             errno = (int) -r;
  31.             return -1;
  32.         }
  33.         return (int) r;
  34.     }
  35.     errno = EINVAL;
  36.     return -1;
  37. }
  38.  
  39. int
  40. readlink(unxname, buf, siz)
  41.     char *unxname, *buf;
  42.     int siz;
  43. {
  44.     long r;
  45.     char filename[PATH_MAX];
  46.     char linkto[PATH_MAX+1];
  47.  
  48.     if (__mint < 9) {
  49.         errno = EINVAL;
  50.         return -1;
  51.     }
  52.     _unx2dos(unxname, filename);
  53.     r = Freadlink(siz, linkto, filename);
  54.     if (r < 0) {
  55.         errno = (int) -r;
  56.         return -1;
  57.     }
  58.     linkto[PATH_MAX] = 0;
  59.     _dos2unx(linkto, buf);
  60.     return (int) strlen(buf);
  61. }
  62.