2 * reactos filesystem name strings functions emulation of libcaptive
3 * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "reactos/ddk/fsfuncs.h" /* self */
23 #include <glib/gmessages.h>
24 #include "captive/unicode.h"
25 #include "reactos/unicode.h" /* for ANSI_* */
26 #include "captive/macros.h"
30 UCHAR **FsRtlLegalAnsiCharacterArray;
34 * captive_FsRtlLegalAnsiCharacterArray_init:
35 * Initialize #FsRtlLegalAnsiCharacterArray character classes
36 * by appropriate #FSRTL_FAT_LEGAL etc. flags.
38 void captive_FsRtlLegalAnsiCharacterArray_init(void)
43 /* Use allocation instead of static array to get ElectricFence sanity boundaries.
44 * Use even the negative 0x80 part as someone may access 'FsRtlLegalAnsiCharacterArray'
45 * with 'signed char' (but also with 'unsigned char'). See also memcpy(3) below.
47 captive_new0n(array,0x80+0x100);
50 for (ui=0;ui<0x100;ui++) {
59 if (ui=='*' || ui=='?')
60 f|=FSRTL_WILD_CHARACTER;
64 array[(unsigned int)(unsigned char)ui]=f;
67 memcpy(array-0x80,array+0x80,0x80*sizeof(*array));
69 FsRtlLegalAnsiCharacterArray=&array;
74 * FsRtlDoesNameContainWildCards:
75 * @Name: Filename to check for wildcards.
76 * %NULL value is forbidden.
77 * Non-zero terminated #PUNICODE_STRING is permitted.
79 * Check if @Name contains wildcard markers as its substring(s).
81 * Returns: %TRUE if @Name contains "*", "?", %ANSI_DOS_STAR, %ANSI_DOS_DOT or %ANSI_DOS_QM.
83 BOOLEAN FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name_nonconst)
85 const UNICODE_STRING *cName=Name_nonconst;
88 g_return_val_if_fail(captive_validate_UnicodeString_noterm(cName),FALSE);
90 for (wcp=cName->Buffer;wcp<cName->Buffer+(cName->Length/sizeof(*cName->Buffer));*wcp++)
94 || *wcp==ANSI_DOS_STAR
104 * @Path: Initialized #UNICODE_STRING to parse.
105 * @FirstName: Returns the first filename from @Path.
106 * %NULL value is forbidden.
107 * @RemainingName: Returns the part of @Path behind @FirstName.
108 * %NULL value is forbidden.
110 * Will parse @Path as regex (FirstName,RemainingName)=/^\?([^/]*)/?(.*)$/;
111 * @FirstName and @RemainingName must be pointers to allocated #UNICODE_STRING
112 * but their #Buffer will be pointing to inside @Path buffer afterwards.
113 * Therefore do not free it! The returned strings may not be 0-terminated strings.
115 VOID FsRtlDissectName(IN UNICODE_STRING Path,OUT PUNICODE_STRING FirstName,OUT PUNICODE_STRING RemainingName)
118 PWSTR delim_FirstName_start ,delim_FirstName_end;
119 PWSTR delim_RemainingName_start,delim_RemainingName_end;
121 g_return_if_fail(captive_validate_UnicodeString(&Path));
122 g_return_if_fail(FirstName!=NULL);
123 g_return_if_fail(RemainingName!=NULL);
125 Path_end=Path.Buffer+Path.Length/sizeof(*Path.Buffer);
127 delim_FirstName_start=Path.Buffer;
128 if (delim_FirstName_start<Path_end && *delim_FirstName_start=='\\')
129 delim_FirstName_start++;
130 for (delim_FirstName_end=delim_FirstName_start;
131 delim_FirstName_end<Path_end && *delim_FirstName_end!='\\';
132 delim_FirstName_end++);
133 delim_RemainingName_start=delim_FirstName_end;
134 if (delim_RemainingName_start<Path_end && *delim_RemainingName_start=='\\')
135 delim_RemainingName_start++;
136 delim_RemainingName_end=Path_end;
138 g_assert(delim_FirstName_start <=delim_FirstName_end);
139 g_assert(delim_FirstName_end <=delim_RemainingName_start);
140 g_assert(delim_RemainingName_start<=delim_RemainingName_end);
142 FirstName->Buffer=delim_FirstName_start;
143 FirstName->Length=(delim_FirstName_end-delim_FirstName_start)*sizeof(*FirstName->Buffer);
144 FirstName->MaximumLength=FirstName->Length;
145 FirstName->Buffer=delim_FirstName_start;
147 RemainingName->Buffer=delim_RemainingName_start;
148 RemainingName->Length=(delim_RemainingName_end-delim_RemainingName_start)*sizeof(*RemainingName->Buffer);
149 RemainingName->MaximumLength=RemainingName->Length;
150 RemainingName->Buffer=delim_RemainingName_start;