grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / filesys / CDVDFS / src / path.c
blob45bcb19d2594f457ae6b6ebccbac53850b7c029f
1 /* path.c:
3 * Path lists.
5 * ----------------------------------------------------------------------
6 * This code is (C) Copyright 1993,1994 by Frank Munkert.
7 * All rights reserved.
8 * This software may be freely distributed and redistributed for
9 * non-commercial purposes, provided this notice is included.
10 * ----------------------------------------------------------------------
11 * History:
13 * 07-Jul-02 sheutlin various changes when porting to AROS
14 * - global variables are now in a struct Globals *global
15 * - moved structure to path.h
18 #include <proto/exec.h>
19 #include <exec/memory.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "generic.h"
24 #include "path.h"
25 #include "globals.h"
27 #include "clib_stuff.h"
29 /* Append p_name to path list: */
31 t_path_list Append_Path_List(t_path_list p_list, char *p_name) {
32 t_path_node *node;
34 if (!(node = AllocMem (sizeof (*node), MEMF_PUBLIC)))
35 return NULL;
37 node->references = 1;
38 if (!(node->name = AllocMem (StrLen (p_name) + 1, MEMF_PUBLIC)))
40 FreeMem (node, sizeof (*node));
41 return NULL;
44 StrCpy (node->name, p_name);
45 node->next = Copy_Path_List (p_list, FALSE);
47 return node;
50 t_path_list Copy_Path_List (t_path_list p_src, int p_strip)
52 t_path_node *node, *start;
54 if (!p_src)
55 return NULL;
57 start = p_strip ? p_src->next : p_src;
59 for (node = start; node; node = node->next) {
60 node->references++;
63 return start;
66 void Free_Path_List(t_path_list p_list) {
67 t_path_node *node, *next;
69 if (!p_list)
70 return;
72 for (node = p_list; node; node = next)
74 next = node->next;
75 if (--node->references == 0)
77 FreeMem (node->name, StrLen (node->name) + 1);
78 FreeMem (node, sizeof (*node));
83 t_bool Path_Name_From_Path_List
84 (t_path_list p_list, char *p_buffer, int p_buffer_length)
86 int len;
87 t_path_node *node;
89 if (!p_list)
91 StrCpy (p_buffer, ":");
92 return TRUE;
95 /* calculate length: */
96 for (len=1, node=p_list; node; node = node->next)
97 len += StrLen (node->name) + 1;
99 if (len > p_buffer_length)
100 return FALSE;
102 for (node=p_list; node; node = node->next)
104 CopyMem
106 node->name,
107 p_buffer + len - StrLen (node->name) - 1,
108 StrLen (node->name)
110 p_buffer[len-1] = (node == p_list) ? 0 : '/';
111 len -= StrLen (node->name) + 1;
113 p_buffer[0] = ':';
114 return TRUE;