本文整理汇总了C++中sfsprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ sfsprintf函数的具体用法?C++ sfsprintf怎么用?C++ sfsprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sfsprintf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pssttydev
Pss_dev_t
pssttydev(register Pss_t* pss, const char* name)
{
register const char* s;
register Tty_t* tty;
struct stat st;
s = name;
if (*s == '?' || *s == '-')
return PSS_NODEV;
if (pss->meth->ttydevf)
return (*pss->meth->ttydevf)(pss, s);
if (tty = (Tty_t*)dtmatch(pss->ttybyname, s))
return tty->dev;
if (stat(s, &st))
{
sfsprintf(pss->buf, sizeof(pss->buf), "/dev/%s", name);
s = (const char*)pss->buf;
if (stat(s, &st))
{
sfsprintf(pss->buf, sizeof(pss->buf), "/dev/tty%s", name);
if (stat(s, &st))
{
if (pss->disc->errorf)
(*pss->disc->errorf)(pss, pss->disc, ERROR_SYSTEM|2, "%s: unknown tty", name);
}
}
}
pssttyadd(pss, name, st.st_rdev);
return st.st_rdev;
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:31,代码来源:pss.c
示例2: init_module
static HANDLE init_module(const char* library)
{
HANDLE h;
char* f;
char buf[PATH_MAX];
static const char sys[] = "C:\\Windows\\System32";
f = "GetModuleHandle";
sfsprintf(buf, sizeof(buf), "%s\\%s.dll", sys, library);
if (h = GetModuleHandle(buf))
goto found;
f = "LoadLibrary";
sfsprintf(buf, sizeof(buf), "%s.dll", library);
if (h = LoadLibrary(buf))
goto found;
sfsprintf(buf, sizeof(buf), "%s\\%s.dll", sys, library);
if (h = LoadLibrary(buf))
goto found;
logmsg(LOGLEVEL(index), "library %s not found", library);
return 0;
found:
logmsg(LOGLEVEL(index), "library %s bound to %s by %s", library, buf, f);
return h;
}
开发者ID:braincat,项目名称:uwin,代码行数:25,代码来源:test_init_mount.c
示例3: exlexname
char*
exlexname(int op, int subop)
{
register char* b;
static int n;
static char buf[TOTNAME][MAXNAME];
if (op > MINTOKEN && op < MAXTOKEN)
return (char*)exop[op - MINTOKEN];
if (++n > TOTNAME)
n = 0;
b = buf[n];
if (op == '=')
{
if (subop > MINTOKEN && subop < MAXTOKEN)
sfsprintf(b, MAXNAME, "%s=", exop[subop - MINTOKEN]);
else if (subop > ' ' && subop <= '~')
sfsprintf(b, MAXNAME, "%c=", subop);
else sfsprintf(b, MAXNAME, "(%d)=", subop);
}
else if (op > ' ' && op <= '~')
sfsprintf(b, MAXNAME, "%c", op);
else sfsprintf(b, MAXNAME, "(%d)", op);
return b;
}
开发者ID:aosm,项目名称:graphviz,代码行数:26,代码来源:exlexname.c
示例4: main
int main(int argc, char** argv)
{
int status;
pid_t pid;
struct spawndata proc;
char cmd[PATH_MAX];
char *name;
int fd;
if(name=strrchr(argv[0],'/'))
name++;
else
name = argv[0];
error_info.id = name;
memset(&proc, 0, sizeof(proc));
proc.flags |= UWIN_TRACE_CALL|UWIN_TRACE_TIME;
if((fd=open("/etc/traceflags",O_RDONLY))>=0)
{
if((status=read(fd,cmd,4))>0)
{
while(--status>=0)
{
if(cmd[status]=='c')
proc.flags |= UWIN_TRACE_COUNT;
else if(cmd[status]=='v')
proc.flags |= UWIN_TRACE_VERBOSE;
else if(cmd[status]=='i')
proc.flags |= UWIN_TRACE_INHERIT;
}
}
close(fd);
}
else
proc.flags |= UWIN_TRACE_VERBOSE|UWIN_TRACE_INHERIT|UWIN_TRACE_COUNT;
sfsprintf(cmd,sizeof(cmd),LOGDIR "trace/%s.log",name);
if ((proc.trace = open(cmd, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0)
error(ERROR_SYSTEM|3, "%s: cannot write", opt_info.arg);
fcntl(proc.trace, F_SETFD, FD_CLOEXEC);
if (error_info.errors || !argv[0])
error(ERROR_USAGE|4, optusage(NiL));
sfsprintf(cmd,sizeof(cmd),LOGDIR "trace/%s",name);
if(access(cmd,X_OK)!=0)
error(ERROR_SYSTEM|ERROR_NOENT, "%s: not found", cmd);
if (!(proc.flags & (UWIN_TRACE_COUNT|UWIN_TRACE_CALL)))
proc.flags |= UWIN_TRACE_CALL;
if ((pid = uwin_spawn(cmd, argv, NiL, &proc)) < 0)
error(ERROR_SYSTEM|ERROR_NOEXEC, "%s: cannot run", cmd);
while (waitpid(pid, &status, 0) == -1)
if (errno != EINTR)
exit(EXIT_NOEXEC);
return(WEXITSTATUS(status));
}
开发者ID:braincat,项目名称:uwin,代码行数:52,代码来源:tracer.c
示例5: tmain
tmain()
{
char buf[100];
Sfio_t *fp;
int i;
char *s;
if(!(fp = sftmp(8)))
terror("Can't open temp file");
sfset(fp,SF_LINE,1);
for(i = 0; i < 1000; ++i)
{ sfsprintf(buf,sizeof(buf),"Number: %d",i);
if(sfputr(fp,buf,'\n') <= 0)
terror("Writing %s",buf);
}
sfseek(fp,(Sfoff_t)0,0);
for(i = 0; i < 1000; ++i)
{ sfsprintf(buf,sizeof(buf),"Number: %d",i);
if(!(s = sfgetr(fp,'\n',1)))
terror("Reading %s",buf);
if(strcmp(s,buf) != 0)
terror("Input=%s, Expect=%s",s,buf);
}
sfseek(fp,(Sfoff_t)0,0);
s = sfgetr(fp,'\0',1);
if(s)
terror("Expecting a null string");
s = sfgetr(fp,'\0',-1);
if(!s)
terror("Expecting a non-null string");
if(sfvalue(fp) != sfsize(fp))
terror("Wrong size");
sfclose(fp);
if(!(fp = sfnew(0, buf, 12, 1, SF_WRITE)) )
terror("Opening a test stream");
sfsetbuf(fp, buf, 12);
sfset(fp, SF_LINE, 0);
sfdisc(fp, &Disc);
if(sfputr(fp, "0123456789", '\n') != 11)
terror("Sfputr failed1");
if(sfputr(fp, "0", -1) != 1)
terror("Sfputr failed2");
if(sfputr(fp, "1", -1) != 1)
terror("Sfputr failed3");
texit(0);
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:52,代码来源:tputgetr.c
示例6: while
char *fmtscale(Sfulong_t n, int k) {
Sfulong_t m;
int r;
int z;
const char *u;
char suf[3];
char *s;
char *buf;
static const char scale[] = "bkMGTPE";
u = scale;
if (n < 1000) {
r = 0;
} else {
m = 0;
while (n >= k && *(u + 1)) {
m = n;
n /= k;
u++;
}
if ((r = (10 * (m % k) + (k / 2)) / k) > 9) {
r = 0;
n++;
}
if (k == 1024 && n >= 1000) {
n = 1;
r = 0;
u++;
}
}
buf = fmtbuf(z = 8);
s = suf;
if (u > scale) {
if (k == 1024) {
*s++ = *u == 'k' ? 'K' : *u;
*s++ = 'i';
} else {
*s++ = *u;
}
}
*s = 0;
if (n > 0 && n < 10) {
char *decimal = nl_langinfo(RADIXCHAR);
sfsprintf(buf, z, "%I*u%s%d%s", sizeof(n), n, decimal, r, suf);
} else {
if (r >= 5) n++;
sfsprintf(buf, z, "%I*u%s", sizeof(n), n, suf);
}
return buf;
}
开发者ID:att,项目名称:ast,代码行数:51,代码来源:fmtscale.c
示例7: fmtelapsed
char*
fmtelapsed(register unsigned long u, register int n)
{
register unsigned long t;
char* buf;
int z;
if (u == 0L)
return "0";
if (u == ~0L)
return "%";
buf = fmtbuf(z = 8);
t = u / n;
if (t < 60)
sfsprintf(buf, z, "%lu.%02lus", t, (u * 100 / n) % 100);
else if (t < 60*60)
sfsprintf(buf, z, "%lum%02lus", t / 60, t - (t / 60) * 60);
else if (t < 24*60*60)
sfsprintf(buf, z, "%luh%02lum", t / (60*60), (t - (t / (60*60)) * (60*60)) / 60);
else if (t < 7*24*60*60)
sfsprintf(buf, z, "%lud%02luh", t / (24*60*60), (t - (t / (24*60*60)) * (24*60*60)) / (60*60));
else if (t < 31*24*60*60)
sfsprintf(buf, z, "%luw%02lud", t / (7*24*60*60), (t - (t / (7*24*60*60)) * (7*24*60*60)) / (24*60*60));
else if (t < 365*24*60*60)
sfsprintf(buf, z, "%luM%02lud", (t * 12) / (365*24*60*60), ((t * 12) - ((t * 12) / (365*24*60*60)) * (365*24*60*60)) / (12*24*60*60));
else if (t < (365UL*4UL+1UL)*24UL*60UL*60UL)
sfsprintf(buf, z, "%luY%02luM", t / (365*24*60*60), ((t - (t / (365*24*60*60)) * (365*24*60*60)) * 5) / (152 * 24 * 60 * 60));
else
sfsprintf(buf, z, "%luY%02luM", (t * 4) / ((365UL*4UL+1UL)*24UL*60UL*60UL), (((t * 4) - ((t * 4) / ((365UL*4UL+1UL)*24UL*60UL*60UL)) * ((365UL*4UL+1UL)*24UL*60UL*60UL)) * 5) / ((4 * 152 + 1) * 24 * 60 * 60));
return buf;
}
开发者ID:NanXiao,项目名称:illumos-joyent,代码行数:31,代码来源:fmtelapsed.c
示例8: pathfind
char*
pathfind(const char* name, const char* lib, const char* type, char* buf, size_t size)
{
register Dir_t* dp;
register char* s;
char tmp[PATH_MAX];
if (access(name, R_OK) >= 0)
return strncpy(buf, name, size);
if (type)
{
sfsprintf(buf, size, "%s.%s", name, type);
if (access(buf, R_OK) >= 0)
return buf;
}
if (*name != '/')
{
if (strchr(name, '.'))
type = 0;
for (dp = state.head; dp; dp = dp->next)
{
sfsprintf(tmp, sizeof(tmp), "%s/%s", dp->dir, name);
if (pathpath(buf, tmp, "", PATH_REGULAR))
return buf;
if (type)
{
sfsprintf(tmp, sizeof(tmp), "%s/%s.%s", dp->dir, name, type);
if (pathpath(buf, tmp, "", PATH_REGULAR))
return buf;
}
}
if (lib)
{
if ((s = strrchr((char*)lib, ':')))
lib = (const char*)s + 1;
sfsprintf(tmp, sizeof(tmp), "lib/%s/%s", lib, name);
if (pathpath(buf, tmp, "", PATH_REGULAR))
return buf;
if (type)
{
sfsprintf(tmp, sizeof(tmp), "lib/%s/%s.%s", lib, name, type);
if (pathpath(buf, tmp, "", PATH_REGULAR))
return buf;
}
}
}
return 0;
}
开发者ID:aosm,项目名称:graphviz,代码行数:48,代码来源:pathfind.c
示例9: setwakeup
static void
setwakeup(void)
{
register Seconds_t t;
register Seconds_t now;
int level;
now = CURSECS;
if (!trap.alarms)
t = 0;
else if (trap.alarms->time <= now)
t = 1;
else
t = trap.alarms->time - now;
alarm(t);
sfsprintf(tmpname, MAXNAME, "%lu", t ? (now + t) : t);
setvar(internal.alarm->name, fmtelapsed(t, 1), 0);
if (error_info.trace <= (level = (state.test & 0x00010000) ? 2 : CMDTRACE))
{
register Alarms_t* a;
if (a = trap.alarms)
{
error(level, "ALARM TIME RULE");
do
{
error(level, "%6s %s %s", fmtelapsed((a->time >= now) ? (a->time - now) : 0, 1), timestr(tmxsns(a->time, 0)), a->rule->name);
} while (a = a->next);
}
else
error(level, "ALARM -- NONE");
}
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:33,代码来源:trap.c
示例10: pdev_lock
HANDLE
pdev_lock(Pdev_t *pdev, int code)
{
HANDLE hp;
SECURITY_ATTRIBUTES sattr;
char mutexName[50];
sattr.nLength = sizeof(sattr);
sattr.lpSecurityDescriptor = nulldacl();
sattr.bInheritHandle = FALSE;
sfsprintf(mutexName,50,"uwin_pdev#%x", block_slot(pdev));
if( (hp = CreateMutex(&sattr,FALSE,mutexName)) == NULL)
logerr(0, "failed to get mutex -- name=[%s] code=[0x%x]", mutexName, code);
else
{
int r;
SetLastError(0);
if((r=WaitForSingleObject(hp,5000))!=WAIT_OBJECT_0)
{
logmsg(0, "WaitForSingleObject failed in mutexlock pdev slot=0x%x code=0x%x", block_slot(pdev), code);
CloseHandle(hp);
hp=0;
}
}
return(hp);
}
开发者ID:braincat,项目名称:uwin,代码行数:25,代码来源:pdev.c
示例11: getFileNames
static void getFileNames (char *dir, char **fileNames, int phyRecSize)
{
DIR *dirp;
struct dirent *entp;
int i = 0;
int extraLen = strlen(dir) + 1 + 1;
if (!(dirp = opendir(dir)))
HRSerrorExit1("Could not find the directory %s\n", dir);
while (entp = readdir(dirp)) {
if ((strcmp(".", entp->d_name) != 0) &&
(strcmp("..", entp->d_name) != 0)) {
int strsize = strlen(entp->d_name) + extraLen;
fileNames[i] = (char *) HRSmalloc(strsize, "getFileNames");
sfsprintf(fileNames[i], strsize, "%s/%s", dir, entp->d_name);
checkStreamFile(fileNames[i], phyRecSize);
i++;
}
}
closedir(dirp);
}
开发者ID:ChappedSky,项目名称:hancock,代码行数:29,代码来源:stream.c
示例12: dllcheck
extern int
dllcheck(void* dll, const char* path, unsigned long ver, unsigned long* cur)
{
unsigned long v;
state.error = 0;
if (ver || cur)
{
v = dllversion(dll, path);
if (cur)
*cur = v;
}
if (!ver)
return 1;
if (!v)
return 0;
if (v < ver)
{
if (path)
{
state.error = 1;
sfsprintf(state.errorbuf, sizeof(state.errorbuf), "plugin version %lu older than caller %lu", v, ver);
errorf("dll", NiL, 1, "dllcheck: %s: %s", path, state.errorbuf);
}
return 0;
}
errorf("dll", NiL, -1, "dllversion: %s: %lu >= %lu", path, v, ver);
return 1;
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:29,代码来源:dllcheck.c
示例13: deleteservice
static int deleteservice(char *account)
{
SC_HANDLE service, scm;
int ret=1, i;
char username[80];
strcpy(username, account);
parse_username(username);
sfsprintf(servname, sizeof(servname),"UWIN_CS%s", username);
sfsprintf(servdname, sizeof(servdname),"UWIN Client(%s)", username);
for(i=0;i<(signed)strlen(servname);i++)
if(servname[i] == '/')
servname[i]= '#';
scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (scm)
{
service = OpenService(scm, servname, SERVICE_ALL_ACCESS);
if (service)
{
if(DeleteService(service))
logmsg(1, "%s deleted", servdname);
else
{
logerr(LOG_STDERR+0, "delete %s failed", servdname);
ret = 0;
}
}
else
{
logerr(LOG_STDERR+0, "%s service open failed", servdname);
ret = 0;
}
CloseServiceHandle(scm);
}
else
{
logerr(LOG_STDERR+0, "OpenSCManager failed");
return(0);
}
return(ret);
}
开发者ID:braincat,项目名称:uwin,代码行数:47,代码来源:ucs.c
示例14: MAIN
MAIN()
{
Sfio_t* f;
char buf[1024], *s;
int n;
#ifdef DEBUG
Sfio_t* logf = sfopen(0,"LOG","a"); sfsetbuf(logf,NIL(Void_t*),0);
#endif
alarm(10);
if(argc > 1)
{ /* coprocess only */
while((s = sfreserve(sfstdin,-1,0)) )
{
#ifdef DEBUG
sfwrite(logf, s, sfvalue(sfstdin));
#endif
sfwrite(sfstdout, s, sfvalue(sfstdin));
}
return 0;
}
/* make coprocess */
if(!(f = sfpopen(NIL(Sfio_t*), sfprints("%s -p",argv[0]), "r+")))
terror("Opening for read/write\n");
for(n = 0; n < 10; ++n)
{ sfsprintf(buf,sizeof(buf),"Line %d",n);
sfputr(f,buf,'\n');
if(!(s = sfgetr(f,'\n',1)))
terror("Did not read back line\n");
if(strcmp(s,buf) != 0)
terror("Input=%s, Expect=%s\n",s,buf);
}
if(sfputr(f,"123456789",'\n') != 10)
terror("Bad write");
if(sfread(f,buf,3) != 3)
terror("Did not get data back\n");
if(strncmp(s,"123",3) != 0)
terror("Wrong data\n");
if(sfwrite(f,"aaa",3) != 3 || sfputc(f,'\n') != '\n')
terror("Fail on write\n");
if(!(s = sfgetr(f,'\n',1)) )
terror("Should have gotten 456789\n");
if(strcmp(s,"456789") != 0)
terror("Wrong data2\n");
if(!(s = sfgetr(f,'\n',1)) )
terror("Should have gotten aaa\n");
if(strcmp(s,"aaa") != 0)
terror("Wrong data3\n");
sfclose(f);
TSTEXIT(0);
}
开发者ID:gwowen,项目名称:seismicunix,代码行数:59,代码来源:tpopenrw.c
示例15: getservname
void getservname(void)
{
DWORD ret,i;
HANDLE tok;
char tmpbuf[1024], UserName[256], RefDomain[256];
PTOKEN_USER UserToken = (PTOKEN_USER)tmpbuf;
DWORD RetLen=1024, UserNameLen, RefDomainLen;
SID_NAME_USE SidType;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tok))
{
if ((ret = GetTokenInformation(tok, TokenUser, UserToken, RetLen, &RetLen)))
{
UserNameLen = sizeof(UserName);
RefDomainLen = sizeof(RefDomain);
if ((ret = LookupAccountSid(NULL,UserToken->User.Sid,UserName,&UserNameLen,RefDomain,&RefDomainLen,&SidType)))
{
strcat(RefDomain,"/");
strcat(RefDomain,UserName);
parse_username(RefDomain);
sfsprintf(servname, sizeof(servname),"UWIN_CS%s", RefDomain);
sfsprintf(servdname, sizeof(servdname),"UWIN Client(%s)", RefDomain);
strcpy(evename,RefDomain);
strcat(evename,"event");
for(i=0;i<strlen(servname);i++)
if(servname[i] == '/')
servname[i]= '#';
{
unsigned char *ptr;
for(ptr=(unsigned char *)evename; *ptr ; ptr++)
*ptr=tolower(*ptr);
}
}
else
logerr(1, "LookupAccountSid failed in getservname");
}
else
logerr(1, "GetTokenInformation failed in getservname");
}
else
logerr(1, "OpenProcessToken failed in getservname");
}
开发者ID:braincat,项目名称:uwin,代码行数:42,代码来源:ucs.c
示例16: sh_regress
void sh_regress(unsigned int index, const char* intercept, const char* info, unsigned int line, const char* file)
{
char* name;
char buf[16];
if (index >= 1 && index <= elementsof(regress_options))
name = (char*)regress_options[index];
else
sfsprintf(name = buf, sizeof(buf), "%u", index);
sfprintf(sfstderr, REGRESS_HEADER "%s:%s:%s\n", name, intercept, fmtesc(info));
}
开发者ID:apprisi,项目名称:illumos-gate,代码行数:11,代码来源:regress.c
示例17: get_enum
static char* get_enum(register Namval_t* np, Namfun_t *fp)
{
static char buff[6];
struct Enum *ep = (struct Enum*)fp;
long n = nv_getn(np,fp);
if(nv_isattr(np,NV_NOTSET)==NV_NOTSET)
return("");
if(n < ep->nelem)
return((char*)ep->values[n]);
sfsprintf(buff,sizeof(buff),"%u%c",n,0);
return(buff);
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:12,代码来源:enum.c
示例18: nv_getn
static_fn char *get_enum(Namval_t *np, Namfun_t *fp) {
if (nv_isattr(np, NV_NOTSET) == NV_NOTSET) return "";
struct Enum *ep = (struct Enum *)fp;
long n = nv_getn(np, fp);
assert(n >= 0);
if (n < ep->nelem) return (char *)ep->values[n];
static char buff[6];
sfsprintf(buff, sizeof(buff), "%u%c", n, 0);
return buff;
}
开发者ID:att,项目名称:ast,代码行数:12,代码来源:enum.c
示例19: error
static void error(int level, char* fmt, ...)
{
DWORD err = GetLastError();
char* cur;
char* end;
char* s;
int n;
char buf[512];
va_list ap;
va_start(ap, fmt);
cur = buf;
end = cur + sizeof(buf) - 1;
cur += sfvsprintf(cur, end - cur, fmt, ap);
va_end(ap);
logerr(LOG_SYSTEM+level, "%s", buf);
if (!quiet)
{
if ((level & LOG_SYSTEM) && err && (int)(end - cur) > 32)
{
cur += sfsprintf(cur, end - cur, "\r\n[%lu:", err);
if (!(n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, 0, cur, (int)(end - cur), 0)))
n = sfsprintf(cur, end - cur, "Unknown error code %d.\n", err);
if (n >= (int)(end - cur))
cur[n-1] = 0;
if (s = strchr(cur, '\n'))
n = (int)(s - cur);
cur += n;
if (*(cur-1) == '\r')
cur--;
if (*(cur-1) == '.')
cur--;
if (cur < end)
*cur++ = ']';
}
*cur = 0;
MessageBox(0, buf, "UWIN Setuid Service", 0x00200000L|0x00040000L|MB_OK|MB_ICONSTOP);
}
}
开发者ID:braincat,项目名称:uwin,代码行数:40,代码来源:ucs.c
示例20: csping
int
csping(register Cs_t* state, const char* name)
{
register int fd;
register int n;
sfsprintf(state->temp, sizeof(state->path), "/dev/tcp/%s/inet.echo", name);
if ((fd = csopen(state, state->temp, 0)) < 0) return -1;
n = (cswrite(state, fd, M, N) != N || csread(state, fd, state->temp, N, CS_LINE) != N || strncmp(M, state->temp, N)) ? -1 : 0;
close(fd);
if (n) messagef((state->id, NiL, -1, "ping: %s: no contact", name));
return n;
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:13,代码来源:csping.c
注:本文中的sfsprintf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论