-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kongxinwei
committed
Mar 4, 2016
1 parent
2e3119c
commit daab64d
Showing
12 changed files
with
779 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* file:get_time.c | ||
*/ | ||
#include <time.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "get_time.h" | ||
|
||
|
||
/* get the time on server, | ||
return: the ascii string of time , NULL on error | ||
argument: time_buf the buffer to store time_string | ||
*/ | ||
|
||
char *get_time_str(char *time_buf) | ||
{ | ||
time_t now_sec; | ||
struct tm *time_now; | ||
if( time(&now_sec) == -1) | ||
{ | ||
perror("time() in get_time.c"); | ||
return NULL; | ||
} | ||
if((time_now = gmtime(&now_sec)) == NULL) | ||
{ | ||
perror("localtime in get_time.c"); | ||
return NULL; | ||
} | ||
char *str_ptr = NULL; | ||
if((str_ptr = asctime(time_now)) == NULL) | ||
{ | ||
perror("asctime in get_time.c"); | ||
return NULL; | ||
} | ||
strcat(time_buf, str_ptr); | ||
return time_buf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef GET_TIME_H | ||
#define GET_TIME_H | ||
|
||
|
||
#define TIME_BUFFER_SIZE 40 /* buffer size of time_buffer */ | ||
|
||
char *get_time_str(char *time_buf); | ||
|
||
|
||
|
||
#endif |
Oops, something went wrong.