哪位兄台有标准C库函数源代码?

smj31 2004-06-10 03:59:25
注意是函数源代码,不是函数用法说明;
本人想进一步学习C语言
...全文
169 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
5420 2004-06-19
  • 打赏
  • 举报
回复
兄台,能不能给我啊????
sevencat 2004-06-10
  • 打赏
  • 举报
回复

@deftypefn Supplemental char* strdup (const char *@var{s})

Returns a pointer to a copy of @var{s} in memory obtained from
@code{malloc}, or @code{NULL} if insufficient memory was available.

@end deftypefn

*/

char *
strdup(s)
char *s;
{
char *result = (char*)malloc(strlen(s) + 1);
if (result == (char*)0)
return (char*)0;
strcpy(result, s);
return result;
}
再贴个GCC的实现,嗯,这下连BCC的实现,也基本上全了。
smj31 2004-06-10
  • 打赏
  • 举报
回复
QQ:42189347
niece 2004-06-10
  • 打赏
  • 举报
回复
/* time.h

Struct and function declarations for dealing with time.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#ifndef _TM_DEFINED
#define _TM_DEFINED

#ifndef __TIME_T
#define __TIME_T
typedef long time_t;
#endif

#ifndef __CLOCK_T
#define __CLOCK_T
typedef long clock_t;
#define CLK_TCK 18.2
#endif

struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};

char *_Cdecl asctime (const struct tm *tblock);
char *_Cdecl ctime (const time_t *time);
double _Cdecl difftime(time_t time2, time_t time1);
struct tm *_Cdecl gmtime(const time_t *timer);
struct tm *_Cdecl localtime(const time_t *timer);
time_t _Cdecl time (time_t *timer);
clock_t _Cdecl clock(void);

#if !__STDC__
extern int _Cdecl daylight;
extern long _Cdecl timezone;

int _Cdecl stime(time_t *tp);
void _Cdecl tzset(void);
#endif

#endif
qr0413356 2004-06-10
  • 打赏
  • 举报
回复
留下联系方法,经常联系一下!!
qr0413356 2004-06-10
  • 打赏
  • 举报
回复
我也有你要做什么??
sevencat 2004-06-10
  • 打赏
  • 举报
回复
/***
*printf.c - print formatted
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines printf() - print formatted data
*
*******************************************************************************/

#include <cruntime.h>
#include <stdio.h>
#include <dbgint.h>
#include <stdarg.h>
#include <file2.h>
#include <internal.h>
#include <mtdll.h>

/***
*int printf(format, ...) - print formatted data
*
*Purpose:
* Prints formatted data on stdout using the format string to
* format data and getting as many arguments as called for
* Uses temporary buffering to improve efficiency.
* _output does the real work here
*
*Entry:
* char *format - format string to control data format/number of arguments
* followed by list of arguments, number and type controlled by
* format string
*
*Exit:
* returns number of characters printed
*
*Exceptions:
*
*******************************************************************************/

int __cdecl printf (
const char *format,
...
)
/*
* stdout 'PRINT', 'F'ormatted
*/
{
va_list arglist;
int buffing;
int retval;

va_start(arglist, format);

_ASSERTE(format != NULL);

#ifdef _MT
_lock_str2(1, stdout);
__try {
#endif /* _MT */

buffing = _stbuf(stdout);

retval = _output(stdout,format,arglist);

_ftbuf(buffing, stdout);

#ifdef _MT
}
__finally {
_unlock_str2(1, stdout);
}
#endif /* _MT */

return(retval);
}
smj31 2004-06-10
  • 打赏
  • 举报
回复
是ANCI C标准的标准库函数
sevencat 2004-06-10
  • 打赏
  • 举报
回复
我先贴一个函数来证明一下。
/***
*strdup.c - duplicate a string in malloc'd memory
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines _strdup() - grab new memory, and duplicate the string into it.
*
*******************************************************************************/

#include <cruntime.h>
#include <malloc.h>
#include <string.h>

/***
*char *_strdup(string) - duplicate string into malloc'd memory
*
*Purpose:
* Allocates enough storage via malloc() for a copy of the
* string, copies the string into the new memory, and returns
* a pointer to it.
*
*Entry:
* char *string - string to copy into new memory
*
*Exit:
* returns a pointer to the newly allocated storage with the
* string in it.
*
* returns NULL if enough memory could not be allocated, or
* string was NULL.
*
*Uses:
*
*Exceptions:
*
*******************************************************************************/

char * __cdecl _strdup (
const char * string
)
{
char *memory;

if (!string)
return(NULL);

if (memory = malloc(strlen(string) + 1))
return(strcpy(memory,string));

return(NULL);
}
sevencat 2004-06-10
  • 打赏
  • 举报
回复
我有VC2003的C库原代码,不过你有报酬吗?
herryhuang 2004-06-10
  • 打赏
  • 举报
回复
gcc
kaphoon 2004-06-10
  • 打赏
  • 举报
回复
linux的/usr/include
下有
sharkhuang 2004-06-10
  • 打赏
  • 举报
回复
gnu源码

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧