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
2861429f
...
2861429f89d347d11c8192019e31c70a829d7bff
authored
2001-06-22 16:31:52 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added mu_get_homedir() and mu_tilde_expansion()
1 parent
3ba66bdc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
2 deletions
include/mailutils/mutil.h
mailbox/mutil.c
include/mailutils/mutil.h
View file @
2861429
...
...
@@ -53,9 +53,12 @@ extern int mu_parse_imap_date_time __P ((const char **p, struct tm * tm,
mu_timezone
*
tz
));
extern
int
mu_parse_ctime_date_time
__P
((
const
char
**
p
,
struct
tm
*
tm
,
mu_timezone
*
tz
));
extern
time_t
mu_utc_offset
__P
((
void
));
extern
time_t
mu_tm2time
__P
((
struct
tm
*
timeptr
,
mu_timezone
*
tz
));
extern
char
*
mu_get_homedir
__P
((
void
));
extern
char
*
mu_tilde_expansion
__P
((
const
char
*
ref
,
const
char
*
delim
,
const
char
*
homedir
));
#ifdef __cplusplus
}
...
...
mailbox/mutil.c
View file @
2861429
...
...
@@ -21,10 +21,13 @@
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include <time.h>
#include <pwd.h>
#include <unistd.h>
#include <mailutils/mutil.h>
/* Convert struct tm into time_t, taking into account timezone offset.
...
...
@@ -34,7 +37,7 @@
NOTE: 1. mktime converts localtime struct tm to *time_t in UTC*
2. adding mu_utc_offset() compensates for the localtime
corrections in
in
mktime(), i.e. it yields the time_t in
corrections in mktime(), i.e. it yields the time_t in
the current zone of struct tm.
3. finally, subtracting TZ offset yields the UTC.
*/
...
...
@@ -204,3 +207,70 @@ mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
}
char
*
mu_get_homedir
(
void
)
{
char
*
homedir
=
getenv
(
"HOME"
);
if
(
!
homedir
)
{
struct
passwd
*
pwd
;
pwd
=
getpwuid
(
getuid
());
if
(
!
pwd
)
return
NULL
;
homedir
=
pwd
->
pw_dir
;
}
return
homedir
;
}
/* NOTE: Allocates Memory. */
/* Expand: ~ --> /home/user and to ~guest --> /home/guest. */
char
*
mu_tilde_expansion
(
const
char
*
ref
,
const
char
*
delim
,
const
char
*
homedir
)
{
char
*
p
=
strdup
(
ref
);
if
(
*
p
==
'~'
)
{
p
++
;
if
(
*
p
==
delim
[
0
]
||
*
p
==
'\0'
)
{
char
*
s
;
if
(
!
homedir
)
{
homedir
=
mu_get_homedir
();
if
(
!
homedir
)
return
NULL
;
}
s
=
calloc
(
strlen
(
homedir
)
+
strlen
(
p
)
+
1
,
1
);
strcpy
(
s
,
homedir
);
strcat
(
s
,
p
);
free
(
--
p
);
p
=
s
;
}
else
{
struct
passwd
*
pw
;
char
*
s
=
p
;
char
*
name
;
while
(
*
s
&&
*
s
!=
delim
[
0
])
s
++
;
name
=
calloc
(
s
-
p
+
1
,
1
);
memcpy
(
name
,
p
,
s
-
p
);
name
[
s
-
p
]
=
'\0'
;
pw
=
getpwnam
(
name
);
free
(
name
);
if
(
pw
)
{
char
*
buf
=
calloc
(
strlen
(
pw
->
pw_dir
)
+
strlen
(
s
)
+
1
,
1
);
strcpy
(
buf
,
pw
->
pw_dir
);
strcat
(
buf
,
s
);
free
(
--
p
);
p
=
buf
;
}
else
p
--
;
}
}
return
p
;
}
...
...
Please
register
or
sign in
to post a comment