
#include<stdio.h>
#include<unistd.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<time.h>
#include<arpa/inet.h>
#include<pthread.h>


#include"zither.h"
#include<almemsys/almemsys.h>

/* int stat_check(char [], char *, int, int *); */


char * stat_check(char * buf, char * filename, int count, int * ret)
{
char bb[count];
char * data = bb;
struct tm tmbuf;
struct stat stat_buf;

if(0 == stat(filename, &stat_buf)){
   if(20<=count){
      localtime_r(&stat_buf.st_mtime, &tmbuf);
      sprintf(data,"%04d:%02d:%02d:%02d:%02d:%02d",
         tmbuf.tm_year + 1900,
         tmbuf.tm_mon + 1,
         tmbuf.tm_mday,
         tmbuf.tm_hour,
         tmbuf.tm_min,
         tmbuf.tm_sec);
      if(0 != memcmp(buf, data, strlen(data))){
         buf = safe_memcpy(buf, data, count); 
         * ret = -1;
         }
      else {
         * ret = 0;
         }
      }
   }
else {
   fprintf(stderr,"stat_check(): not get file stat %s\n", filename);
   buf = safe_memcpy(buf, "0", count); 
   * ret = -2;
   }
return buf;
}  






