File: mac-alias.c

package info (click to toggle)
squeak-vm 1%3A4.10.2.2614-4.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,284 kB
  • ctags: 15,344
  • sloc: ansic: 75,096; cs: 11,191; objc: 5,494; sh: 3,170; asm: 1,533; cpp: 449; pascal: 372; makefile: 366; awk: 103
file content (40 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Based on code contributed by Tom Rushworth.
 * Mutilated beyond recognition by Ian Piumarta.
 * 
 * last edited: 2006-04-24 15:38:40 by piumarta on emilia.local
 */

#include <CoreServices/CoreServices.h>		/* see sqGetFilenameFromString() */

/* Answer nonzero if path describes an OS X alias file. */

static sqInt isMacAlias(char *path)
{
  Boolean  isAlias=  false;
  Boolean  isFolder= false;
  FSRef	   fileRef;		/* No need to dispose of this. */
  FSRef	  *frp= &fileRef;

  return (noErr == FSPathMakeRef((UInt8 *)path, frp, &isFolder))	/* POSIX path -> OS X FSRef */
    &&   (noErr == FSIsAliasFile(frp, &isAlias, &isFolder))		/* test for alias */
    &&   isAlias;
}


/* Resolve aliases in the src path leaving the result in dst.
   Answer nonzero if successful.
   Note: dst and src may refer to the same buffer. */

static sqInt resolveMacAlias(char *dst, char *src, sqInt max_length)
{
  Boolean wasAlias= false;
  Boolean isFolder= false;
  FSRef	  fileRef;	/* No need to dispose of this. */
  FSRef	 *frp= &fileRef;

  return (noErr == FSPathMakeRef((UInt8 *)src, frp, &isFolder))			/* POSIX path -> OS X FSRef */
    &&   (noErr == FSResolveAliasFileWithMountFlags(frp, true,			/* resolve */
						    &isFolder, &wasAlias,
						    kResolveAliasFileNoUI))
    &&   (noErr == FSRefMakePath(frp, (UInt8 *)dst, PATH_MAX));			/* resolved FSRef -> POSIX path */
}