设为首页 加入收藏

TOP

TSDK.H 开发包(一)
2014-11-24 00:40:13 来源: 作者: 【 】 浏览:83
Tags:TSDK.H 开发包

T-ware Inc.
C 语言开发包

[cpp]
/*
TSDK.H

Definitions for Common functions and string functions.

Copyright (c) Tody 2010
All Rights Reserved
*/

#ifndef __TSDK_H__
#define __TSDK_H__

#include
#include
#include

#if __STDC__
# define _Cdecl
#else
# define _Cdecl cdecl
#endif

#ifndef DOS
# define SAY(x...) printf(x)
#else
# define SAY(x) printf(x)
#endif

#ifndef MAX
# define MAX(a, b) ((a) < (b) (b) : (a))
#endif
#ifndef MIN
# define MIN(a, b) ((a) < (b) (a) : (b))
#endif

#define FATAL(x) do { \
printf("\n[-] PROGRAM ABORT : %s", x); \
exit(1); \
} while (0)

#define VERSION "1.0.0"

#define true 1
#define false 0

typedef char bool;


/* Function Declare */
bool _Cdecl copy_file (char *scr_file, char *dst_file, int flag);
bool _Cdecl file_exist (char *file);

char *_Cdecl skip_spaces (const char *str);
char *_Cdecl strim (char *p);
int _Cdecl t_random (int a, int b);
bool _Cdecl log_save (char *log_file, char *ErrMsg);

bool _Cdecl is_leap_yaer(int year);
int _Cdecl which_day (int year, int mon, int day);

bool _Cdecl is_little_endian( void );

/*******************************************************************
* Remove leading whitespace string
*******************************************************************/
char *skip_spaces(const char *str)
{
while (isspace(*str))
++str;
return (char *)str;
}

/*******************************************************************
* Remove Left and right blank of string
*******************************************************************/
char *strim(char *s)
{
size_t size;
char *end;

s = skip_spaces(s);
size = strlen(s);
if (!size)
return s;

end = s + size - 1;
while (end >= s && isspace(*end))
end--;
*(end + 1) = '\0';

return s;
}

/*******************************************************************
* Random a number between a and b (not contain b)
*******************************************************************/
int t_random (int a, int b)
{
if (a >= b) return -1;
srand(time(NULL)); /* Seed is time */
return (rand()%(b-a) + a);
}

/*******************************************************************
* Copy file from scr_file to des_file
*******************************************************************/
bool copy_file (char *scr_file, char *des_file, int flag)
{
FILE *fin,*fout;
char ch;

if (0 == flag && file_exist(des_file) == 1) return false;

if ((fin=fopen(scr_file, "rb")) == NULL)
{
return false;
}
if ((fout=fopen(des_file, "wb")) == NULL)
{
return false;
}

ch = fgetc(fin); /* File copying... */
while ( ch != EOF)
{
fputc(ch, fout);
ch = fgetc(fin);
}

fclose(fout);
fclose(fin);
return true;
}

/*******************************************************************
* Check file is exist or not
*******************************************************************/
bool file_exist (char *file)
{
return !access(file,0); /* File exist, access() return 0, else return -1 */
}

/*******************************************************************
*

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇switch case 疑点解析 下一篇c语言中swap问题小结

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: