#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>

int lib_gmtime(void)
{               /* On VMS correct to make it a GMT time.  */
        time_t t;
        time(&t);
	return t;
   /*     return (int) lib_fixtime(t);  Convert to STD base date of 1970 */
}

char *ncpy(char *dst, char *src, int len)
{
        char *xdst = dst;
        int xlen = len;
        for (;(*src !=0) && (len>0); ) {*dst++  = *src++; len--;}
        *dst++ = 0;
        xdst[xlen] = 0;
        return xdst;
}
void *check_malloc(size_t t, char *file, int line)
{
	return malloc(t);	
}
void check_free(void *m, char *file, int line)
{
	free(m);
}
char *mystrdup(const char *s)
{
  int xlen = strlen(s)+1;
  char *n;
  n = check_malloc(xlen,"ftslib2",1);
  strcpy(n,s);
  return n;
}
/*------------------------------------------------*/

void fts_log_msg(char *s);
void dmsg(char * arg_list, ...)
{
        va_list arg_ptr;
        char *format;
     	char output[1000];
        int len;
	return;
        va_start(arg_ptr, arg_list);
        format = arg_list;
        len = vsnprintf(output, BFSZ-1, format, arg_ptr);
	output[BFSZ-1] = 0;
	printf("%s",output);
}
void filemsg(char * arg_list, ...)
{
        va_list arg_ptr;
        char *format;
     	char output[1000];
        int len;
        va_start(arg_ptr, arg_list);
        format = arg_list;
        len = vsnprintf(output, BFSZ-1, format, arg_ptr);
	output[BFSZ-1] = 0;
	perror(output);
	fts_log_msg(output);
}
void imsg(char * arg_list, ...)
{
        va_list arg_ptr;
        char *format;
     	char output[1000];
        int len;
        va_start(arg_ptr, arg_list);
        format = arg_list;
        len = vsprintf(output,BFSZ-1, format, arg_ptr);
	output[BFSZ-1] = 0;
	printf("%s",output);
	fts_log_msg(output);
}
int emsg(char * arg_list, ...)
{
        va_list arg_ptr;
        char *format;
     	char output[1000];
        int len;
        va_start(arg_ptr, arg_list);
        format = arg_list;
        len = vsprintf(output,BFSZ-1, format, arg_ptr);
	output[BFSZ-1] = 0;
	printf("%s",output);
	fts_log_msg(output);
}
void fts_log_msg(char *s)
{
	static FILE *f;
	if (f==NULL) f = fopen("fts.log","a");
	fprintf(f,"%s",s);
}
char *mystrchr(const char *s,const int c);
char *mystrstr(const char *s, const char *w)
{
        const char *ww = w;
        int len = strlen(w);

        for (;*s!=0;) {
                s = mystrchr(s,*w);
                if (s==NULL) return NULL;
                if (strncmp(s,w,len)==0) return (char *) s;
                s++;
        }
        return NULL;
}
char *mystrchr(const char *s,const int c)
{
 	for (;*s!=0;s++) if (*s==c) return (char *) s;
	return NULL;
}
