Ace_OS 命名空间记录

本文详细记录了Ace_OS命名空间的内容,包括其在操作系统接口(os)、API调用、POSIX标准和Windows API(win32)方面的应用。通过对Ace_OS的深入探讨,帮助读者理解和使用这个强大的工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This namespace defines an OS independent programming API that shields developers from nonportable aspects of writing efficient system programs on Win32, POSIX and other versions of UNIX, and various real-time operating systems.

This class is a wrapper for the XTI/TLI operations.

This namespace encapsulates the differences between various OS platforms. When porting ACE to a new platform, this class is the place to focus on. Once this file is ported to a new platform, pretty much everything else comes for "free." See <www.cs.wustl.edu/~schmidt/ACE_wrappers/etc/ACE-porting.html> for instructions on porting ACE. Please see the README file in this directory for complete information on the meaning of the various macros. 
说得很厉害一样,就是实现了跨平台功能,才用ACE_OS 这个命名空间来封装。

头文件 "ace/OS_NS_fcntl.h" 下的函数:
    1 ACE_HANDLE open (const char *filename,
                   int mode,
                   mode_t perms = ACE_DEFAULT_OPEN_PERMS,
                   LPSECURITY_ATTRIBUTES sa = 0);//打开一个文件;
    2    int fcntl (ACE_HANDLE handle,
             int cmd,
             long arg = 0);
头文件  "ace/OS_NS_stdio.h"下的函数:
   1 int sprintf (char *buf, const char *format, ...);
   2 int vasprintf (char **bufp, const char *format, va_list argptr);

头文件 “ace/OS_NS_stdlib.h” 下的函数://相当于c 语言中的 stdlib.h,包括内存的申请和释放
   1 int atoi (const char *s);
   2 long atol (const char *s);
   3 void free (void *);
   4 int setenv(const char *envname, const char *envval, int overwrite); 等函数。

头文件 “ace/OS_NS_pwd.h” 下的函数:
   1 struct passwd *getpwnam (const char *user);

头文件 “ace/OS_NS_unistd.h” 下的函数:
   1 int access (const char *path, int amode);
   2 int argv_to_string (ACE_TCHAR **argv,
                      ACE_TCHAR *&buf,
                      bool substitute_env_args = true,
                      bool quote_args = false);
   3 int rmdir (const char *path);
   4 pid_t fork (void); 等函数
   5 int sleep (u_int seconds);

头文件 "ace/OS_NS_string.h"下的函数://字符串操作
   1 char *strcpy (char *s, const char *t);
   2 int strcmp (const ACE_WCHAR_T *s, const ACE_WCHAR_T *t);
   3 void *memset (void *s, int c, size_t len);

头文件  "ace/os_include/os_netdb.h" 包含 MAXHOSTNAMELEN 的定义。

static __time64_t __cdecl _make__time64_t ( struct tm *tb, int ultflag ) { __time64_t tmptm1, tmptm2, tmptm3; struct tm tbtemp; long dstbias = 0; long timezone = 0; _VALIDATE_RETURN( ( tb != NULL ), EINVAL, ( ( __time64_t )( -1 ) ) ) /* * First, make sure tm_year is reasonably close to being in range. */ if ( ((tmptm1 = tb->tm_year) _MAX_YEAR64 + 1) ) goto err_mktime; /* * Adjust month value so it is in the range 0 - 11. This is because * we don't know how many days are in months 12, 13, 14, etc. */ if ( (tb->tm_mon tm_mon > 11) ) { tmptm1 += (tb->tm_mon / 12); if ( (tb->tm_mon %= 12) tm_mon += 12; tmptm1--; } /* * Make sure year count is still in range. */ if ( (tmptm1 _MAX_YEAR64 + 1) ) goto err_mktime; } /***** HERE: tmptm1 holds number of elapsed years *****/ /* * Calculate days elapsed minus one, in the given year, to the given * month. Check for leap year and adjust if necessary. */ tmptm2 = _days[tb->tm_mon]; if ( _IS_LEAP_YEAR(tmptm1) && (tb->tm_mon > 1) ) tmptm2++; /* * Calculate elapsed days since base date (midnight, 1/1/70, UTC) * * * 365 days for each elapsed year since 1970, plus one more day for * each elapsed leap year. no danger of overflow because of the range * check (above) on tmptm1. */ tmptm3 = (tmptm1 - _BASE_YEAR) * 365 + _ELAPSED_LEAP_YEARS(tmptm1); /* * elapsed days to current month (still no possible overflow) */ tmptm3 += tmptm2; /* * elapsed days to current date. */ tmptm1 = tmptm3 + (tmptm2 = (__time64_t)(tb->tm_mday)); /***** HERE: tmptm1 holds number of elapsed days *****/ /* * Calculate elapsed hours since base date */ tmptm2 = tmptm1 * 24; tmptm1 = tmptm2 + (tmptm3 = (__time64_t)tb->tm_hour); /***** HERE: tmptm1 holds number of elapsed hours *****/ /* * Calculate elapsed minutes since base date */ tmptm2 = tmptm1 * 60; tmptm1 = tmptm2 + (tmptm3 = (__time64_t)tb->tm_min); /***** HERE: tmptm1 holds number of elapsed minutes *****/ /* * Calculate elapsed seconds since base date */ tmptm2 = tmptm1 * 60; tmptm1 = tmptm2 + (tmptm3 = (__time64_t)tb->tm_sec); /***** HERE: tmptm1 holds number of elapsed seconds *****/ if ( ultflag ) { /* * Adjust for timezone. No need to check for overflow since * localtime() will check its arg value */ __tzset(); _ERRCHECK(_get_dstbias(&dstbias;)); _ERRCHECK(_get_timezone(&timezone;)); tmptm1 += timezone; /* * Convert this second count back into a time block structure. * If localtime returns NULL, return an error. */ if ( _localtime64_s(&tbtemp;, &tmptm1;) != 0 ) goto err_mktime; /* * Now must compensate for DST. The ANSI rules are to use the * passed-in tm_isdst flag if it is non-negative. Otherwise, * compute if DST applies. Recall that tbtemp has the time without * DST compensation, but has set tm_isdst correctly. */ if ( (tb->tm_isdst > 0) || ((tb->tm_isdst 0)) ) { tmptm1 += dstbias; if ( _localtime64_s(&tbtemp;, &tmptm1;) != 0 ) goto err_mktime; } } else { if ( _gmtime64_s(&tbtemp;, &tmptm1;) != 0) goto err_mktime; } /***** HERE: tmptm1 holds number of elapsed seconds, adjusted *****/ /***** for local time if requested *****/ *tb = tbtemp; return tmptm1; err_mktime: /* * All errors come to here */ errno = EINVAL; return (__time64_t)(-1); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值