Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
9804997b
Commit
9804997b
authored
Feb 25, 2014
by
mk-pmb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pick home and config path from environment if set.
parent
6132516d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
main.c
main.c
+12
-6
No files found.
main.c
View file @
9804997b
...
@@ -151,11 +151,16 @@ void set_terminal_attributes (void) {
...
@@ -151,11 +151,16 @@ void set_terminal_attributes (void) {
}
}
/* }}} */
/* }}} */
int
str_empty
(
char
*
str
)
{
return
((
str
==
NULL
)
||
(
strlen
(
str
)
<
1
));
}
char
*
get_home_directory
(
void
)
{
char
*
get_home_directory
(
void
)
{
static
char
*
home_directory
=
NULL
;
static
char
*
home_directory
=
NULL
;
if
(
home_directory
!=
NULL
)
{
home_directory
=
getenv
(
"TELEGRAM_HOME"
);
return
home_directory
;
if
(
!
str_empty
(
home_directory
))
{
return
tstrdup
(
home_directory
);
}
}
home_directory
=
getenv
(
"HOME"
);
if
(
!
str_empty
(
home_directory
))
{
return
tstrdup
(
home_directory
);
}
struct
passwd
*
current_passwd
;
struct
passwd
*
current_passwd
;
uid_t
user_id
;
uid_t
user_id
;
setpwent
();
setpwent
();
...
@@ -167,14 +172,14 @@ char *get_home_directory (void) {
...
@@ -167,14 +172,14 @@ char *get_home_directory (void) {
}
}
}
}
endpwent
();
endpwent
();
if
(
home_directory
==
NULL
)
{
if
(
str_empty
(
home_directory
))
{
home_directory
=
tstrdup
(
"."
);
}
home_directory
=
tstrdup
(
"."
);
}
return
home_directory
;
return
home_directory
;
}
}
char
*
get_config_directory
(
void
)
{
char
*
get_config_directory
(
void
)
{
char
*
config_directory
;
char
*
config_directory
;
config_directory
=
getenv
(
"TELEGRAM_CONFIG_DIR"
);
if
(
!
str_empty
(
config_directory
))
{
return
tstrdup
(
config_directory
);
}
tasprintf
(
&
config_directory
,
"%s/"
CONFIG_DIRECTORY
,
get_home_directory
());
tasprintf
(
&
config_directory
,
"%s/"
CONFIG_DIRECTORY
,
get_home_directory
());
return
config_directory
;
return
config_directory
;
}
}
...
@@ -249,6 +254,7 @@ void running_for_first_time (void) {
...
@@ -249,6 +254,7 @@ void running_for_first_time (void) {
config_file_fd
=
open
(
config_filename
,
O_CREAT
|
O_RDWR
,
0600
);
config_file_fd
=
open
(
config_filename
,
O_CREAT
|
O_RDWR
,
0600
);
if
(
config_file_fd
==
-
1
)
{
if
(
config_file_fd
==
-
1
)
{
perror
(
"open[config_file]"
);
perror
(
"open[config_file]"
);
printf
(
"I: config_file=[%s]
\n
"
,
config_filename
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
write
(
config_file_fd
,
DEFAULT_CONFIG_CONTENTS
,
strlen
(
DEFAULT_CONFIG_CONTENTS
))
<=
0
)
{
if
(
write
(
config_file_fd
,
DEFAULT_CONFIG_CONTENTS
,
strlen
(
DEFAULT_CONFIG_CONTENTS
))
<=
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment