summaryrefslogtreecommitdiffstats
path: root/common/os_calls.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/os_calls.c')
-rw-r--r--common/os_calls.c82
1 files changed, 67 insertions, 15 deletions
diff --git a/common/os_calls.c b/common/os_calls.c
index 692dc015..211adc82 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -415,7 +415,6 @@ g_tcp_close(int sck)
{
return;
}
- shutdown(sck, 2);
#if defined(_WIN32)
closesocket(sck);
#else
@@ -563,31 +562,33 @@ g_tcp_accept(int sck)
/*****************************************************************************/
void APP_CC
-g_write_ip_address(int rcv_sck, char* ip_address)
+g_write_ip_address(int rcv_sck, char* ip_address, int bytes)
{
struct sockaddr_in s;
struct in_addr in;
int len;
int ip_port;
+ int ok;
- memset(&s,0,sizeof(&s));
+ ok = 0;
+ memset(&s, 0, sizeof(s));
len = sizeof(s);
- getpeername(rcv_sck,(struct sockaddr*)&s, &len);
-
- memset(&in,0,sizeof(in));
- in.s_addr = s.sin_addr.s_addr;
-
- ip_port = ntohs(s.sin_port);
-
- if (ip_port != 0)
+ if (getpeername(rcv_sck,(struct sockaddr*)&s, &len) == 0)
{
- sprintf(ip_address, "%s:%d - socket: %d", inet_ntoa(in), ip_port, rcv_sck);
+ memset(&in, 0, sizeof(in));
+ in.s_addr = s.sin_addr.s_addr;
+ ip_port = ntohs(s.sin_port);
+ if (ip_port != 0)
+ {
+ ok = 1;
+ snprintf(ip_address, bytes, "%s:%d - socket: %d", inet_ntoa(in),
+ ip_port, rcv_sck);
+ }
}
- else
+ if (!ok)
{
- sprintf(ip_address, "NULL:NULL - socket: %d", rcv_sck);
+ snprintf(ip_address, bytes, "NULL:NULL - socket: %d", rcv_sck);
}
-
}
/*****************************************************************************/
@@ -998,6 +999,19 @@ g_delete_wait_obj(tbus obj)
/*****************************************************************************/
/* returns error */
+/* close but do not delete the wait obj, used after fork */
+int APP_CC
+g_close_wait_obj(tbus obj)
+{
+#ifdef _WIN32
+#else
+ close((int)obj);
+#endif
+ return 0;
+}
+
+/*****************************************************************************/
+/* returns error */
int APP_CC
g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount,
int mstimeout)
@@ -1391,6 +1405,44 @@ g_create_dir(const char* dirname)
}
/*****************************************************************************/
+/* will try to create directories up to last / in name
+ example /tmp/a/b/c/readme.txt will try to create /tmp/a/b/c
+ returns boolean */
+int APP_CC
+g_create_path(const char* path)
+{
+ char* pp;
+ char* sp;
+ char* copypath;
+ int status;
+
+ status = 1;
+ copypath = g_strdup(path);
+ pp = copypath;
+ sp = strchr(pp, '/');
+ while (sp != 0)
+ {
+ if (sp != pp)
+ {
+ *sp = 0;
+ if (!g_directory_exist(copypath))
+ {
+ if (!g_create_dir(copypath))
+ {
+ status = 0;
+ break;
+ }
+ }
+ *sp = '/';
+ }
+ pp = sp + 1;
+ sp = strchr(pp, '/');
+ }
+ g_free(copypath);
+ return status;
+}
+
+/*****************************************************************************/
/* returns boolean */
int APP_CC
g_remove_dir(const char* dirname)