Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
038f7416
...
038f7416553fc487b999ed55ffc9e033f5ffa06e
authored
2002-06-27 09:13:45 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
(mu_expand_path_pattern): new function
1 parent
8b40ce89
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
mailbox/mutil.c
mailbox/mutil.c
View file @
038f741
...
...
@@ -973,3 +973,95 @@ mu_unroll_symlink (char *out, size_t outsz, const char *in)
return
0
;
}
/* Expand a PATTERN to the pathname. PATTERN may contain the following
macro-notations:
---------+------------
notation | expands to
---------+------------
%u user name
%h user's home dir
---------+------------
Allocates memory.
*/
char
*
mu_expand_path_pattern
(
const
char
*
pattern
,
const
char
*
username
)
{
char
*
homedir
=
NULL
;
const
char
*
p
,
*
startp
;
char
*
q
;
char
*
path
;
int
len
=
0
;
for
(
p
=
pattern
;
*
p
;
p
++
)
{
if
(
*
p
==
'%'
)
switch
(
*++
p
)
{
case
'u'
:
len
+=
strlen
(
username
);
break
;
case
'h'
:
if
(
!
homedir
)
{
struct
passwd
*
pwd
=
mu_getpwnam
(
username
);
if
(
!
pwd
)
return
NULL
;
homedir
=
pwd
->
pw_dir
;
}
len
+=
strlen
(
homedir
);
break
;
case
'%'
:
len
++
;
break
;
default:
len
+=
2
;
}
else
len
++
;
}
path
=
malloc
(
len
+
1
);
if
(
!
path
)
return
NULL
;
startp
=
pattern
;
q
=
path
;
while
(
*
startp
&&
(
p
=
strchr
(
startp
,
'%'
))
!=
NULL
)
{
memcpy
(
q
,
startp
,
p
-
startp
);
q
+=
p
-
startp
;
switch
(
*++
p
)
{
case
'u'
:
strcpy
(
q
,
username
);
q
+=
strlen
(
username
);
break
;
case
'h'
:
strcpy
(
q
,
homedir
);
q
+=
strlen
(
homedir
);
break
;
case
'%'
:
*
q
++
=
'%'
;
break
;
default:
*
q
++
=
'%'
;
*
q
++
=
*
p
;
}
startp
=
p
+
1
;
}
if
(
*
startp
)
{
strcpy
(
q
,
startp
);
q
+=
strlen
(
startp
);
}
*
q
=
0
;
return
path
;
}
...
...
Please
register
or
sign in
to post a comment