projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added SILC Server library.
[silc.git]
/
lib
/
silcutil
/
unix
/
silcunixutil.c
diff --git
a/lib/silcutil/unix/silcunixutil.c
b/lib/silcutil/unix/silcunixutil.c
index 2dc40e142a62b8eff70a7a53baaf4edd483616ac..15356c52b92b474f40b0f5e01c27a709920ad948 100644
(file)
--- a/
lib/silcutil/unix/silcunixutil.c
+++ b/
lib/silcutil/unix/silcunixutil.c
@@
-2,14
+2,13
@@
silcunixutil.c
silcunixutil.c
- Author: Pekka Riikonen <priikone@sil
l
cnet.org>
+ Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 200
1
Pekka Riikonen
+ Copyright (C) 1997 - 200
5
Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-23,7
+22,7
@@
*/
/* $Id$ */
*/
/* $Id$ */
-#include "silc
includes
.h"
+#include "silc.h"
/* XXX lib/contrib/regex.c might cmopile on WIN32 as well */
/* XXX lib/contrib/regex.c might cmopile on WIN32 as well */
@@
-38,31
+37,35
@@
char *silc_string_regexify(const char *string)
len = strlen(string);
count = 4;
len = strlen(string);
count = 4;
- for (i = 0; i < len; i++)
+ for (i = 0; i < len; i++)
{
if (string[i] == '*' || string[i] == '?')
if (string[i] == '*' || string[i] == '?')
- count++;
+ count++; /* Will add '.' */
+ if (string[i] == ',')
+ count += 2; /* Will add '|' and '^' */
+ }
- regex = silc_calloc(len + count, sizeof(*regex));
+ regex = silc_calloc(len + count
+ 1
, sizeof(*regex));
count = 0;
count = 0;
- regex[count] = '(';
-
count++
;
+ regex[count
++
] = '(';
+
regex[count++] = '^'
;
for (i = 0; i < len; i++) {
if (string[i] == '*' || string[i] == '?') {
regex[count] = '.';
count++;
} else if (string[i] == ',') {
for (i = 0; i < len; i++) {
if (string[i] == '*' || string[i] == '?') {
regex[count] = '.';
count++;
} else if (string[i] == ',') {
- regex[count] = '|';
- count++;
+ if (i + 2 == len)
+ continue;
+ regex[count++] = '|';
+ regex[count++] = '^';
continue;
}
continue;
}
- regex[count] = string[i];
- count++;
+ regex[count++] = string[i];
}
}
- regex[count
- 1
] = ')';
+ regex[count
++
] = ')';
regex[count] = '$';
return regex;
regex[count] = '$';
return regex;
@@
-95,7
+98,7
@@
int silc_string_regex_match(const char *regex, const char *string)
regex_t preg;
int ret = FALSE;
regex_t preg;
int ret = FALSE;
- if (regcomp(&preg, regex, REG_NOSUB | REG_EXTENDED)
<
0)
+ if (regcomp(&preg, regex, REG_NOSUB | REG_EXTENDED)
!=
0)
return FALSE;
if (regexec(&preg, string, 0, NULL, 0) == 0)
return FALSE;
if (regexec(&preg, string, 0, NULL, 0) == 0)
@@
-114,6
+117,9
@@
int silc_string_match(const char *string1, const char *string2)
char *s1;
int ret = FALSE;
char *s1;
int ret = FALSE;
+ if (!string1 || !string2)
+ return ret;
+
s1 = silc_string_regexify(string1);
ret = silc_string_regex_match(s1, string2);
silc_free(s1);
s1 = silc_string_regexify(string1);
ret = silc_string_regex_match(s1, string2);
silc_free(s1);
@@
-135,17
+141,15
@@
char *silc_get_username()
struct passwd *pw;
pw = getpwuid(getuid());
struct passwd *pw;
pw = getpwuid(getuid());
- if (!pw) {
- fprintf(stderr, "silc_get_username: %s\n", strerror(errno));
- return NULL;
- }
-
+ if (!pw)
+ return strdup("foo");
+
logname = pw->pw_name;
}
}
return strdup(logname);
logname = pw->pw_name;
}
}
return strdup(logname);
-}
+}
/* Returns the real name of ther user. */
/* Returns the real name of ther user. */
@@
-155,10
+159,8
@@
char *silc_get_real_name()
struct passwd *pw;
pw = getpwuid(getuid());
struct passwd *pw;
pw = getpwuid(getuid());
- if (!pw) {
- fprintf(stderr, "silc_get_username: %s\n", strerror(errno));
- return NULL;
- }
+ if (!pw)
+ return strdup("Foo T. Bar");
if (strchr(pw->pw_gecos, ','))
*strchr(pw->pw_gecos, ',') = 0;
if (strchr(pw->pw_gecos, ','))
*strchr(pw->pw_gecos, ',') = 0;
@@
-167,3
+169,16
@@
char *silc_get_real_name()
return realname;
}
return realname;
}
+
+/* Return current time to struct timeval. */
+
+int silc_gettimeofday(struct timeval *p)
+{
+ return gettimeofday(p, NULL);
+}
+
+int silc_file_set_nonblock(int fd)
+{
+ return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+}
+