1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * prof_FSp_glue.c --- Deprecated FSSpec functions. Mac-only.
4 */
5
6 #include "prof_int.h"
7
8 #include <Kerberos/FSpUtils.h>
9 #include <limits.h>
10
11 long KRB5_CALLCONV FSp_profile_init (const FSSpec* files, profile_t *ret_profile);
12
13 long KRB5_CALLCONV FSp_profile_init_path (const FSSpec* files, profile_t *ret_profile);
14
15 errcode_t KRB5_CALLCONV
FSp_profile_init(files,ret_profile)16 FSp_profile_init(files, ret_profile)
17 const FSSpec* files;
18 profile_t *ret_profile;
19 {
20 unsigned int fileCount = 0;
21 const FSSpec *nextSpec;
22 profile_filespec_t *pathArray = NULL;
23 unsigned int i;
24 errcode_t retval = 0;
25
26 for (nextSpec = files; ; nextSpec++) {
27 if ((nextSpec -> vRefNum == 0) &&
28 (nextSpec -> parID == 0) &&
29 (StrLength (nextSpec -> name) == 0))
30 break;
31 fileCount++;
32 }
33
34 pathArray = (profile_filespec_t *) malloc ((fileCount + 1) * sizeof(const_profile_filespec_t));
35 if (pathArray == NULL) {
36 retval = ENOMEM;
37 }
38
39 if (retval == 0) {
40 for (i = 0; i < fileCount + 1; i++) {
41 pathArray [i] = NULL;
42 }
43 }
44
45 if (retval == 0) {
46 for (i = 0; i < fileCount; i++) {
47 OSStatus err = noErr;
48
49 if (err == noErr) {
50 pathArray[i] = (char *) malloc (sizeof(char) * PATH_MAX);
51 if (pathArray[i] == NULL) {
52 err = memFullErr;
53 }
54 }
55 /* convert the FSSpec to an path */
56 if (err == noErr) {
57 err = FSSpecToPOSIXPath (&files[i], pathArray[i], PATH_MAX);
58 }
59
60 if (err == memFullErr) {
61 retval = ENOMEM;
62 break;
63 } else if (err != noErr) {
64 retval = ENOENT;
65 break;
66 }
67 }
68 }
69
70 if (retval == 0) {
71 retval = profile_init ((const_profile_filespec_t *) pathArray,
72 ret_profile);
73 }
74
75 if (pathArray != NULL) {
76 for (i = 0; i < fileCount; i++) {
77 if (pathArray [i] != 0)
78 free (pathArray [i]);
79 }
80 free (pathArray);
81 }
82
83 return retval;
84 }
85
86 errcode_t KRB5_CALLCONV
FSp_profile_init_path(files,ret_profile)87 FSp_profile_init_path(files, ret_profile)
88 const FSSpec* files;
89 profile_t *ret_profile;
90 {
91 return FSp_profile_init (files, ret_profile);
92 }
93