Skip to content

Commit

Permalink
add webserver source code
Browse files Browse the repository at this point in the history
  • Loading branch information
kongxinwei committed Mar 4, 2016
1 parent 2e3119c commit daab64d
Show file tree
Hide file tree
Showing 12 changed files with 779 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tools/webserver/get_time.c
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;
}
11 changes: 11 additions & 0 deletions tools/webserver/get_time.h
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
Loading

0 comments on commit daab64d

Please sign in to comment.