本文整理汇总了C++中STRNCPY函数的典型用法代码示例。如果您正苦于以下问题:C++ STRNCPY函数的具体用法?C++ STRNCPY怎么用?C++ STRNCPY使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STRNCPY函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_sequence
static void
add_sequence(char *rest, char *mapname)
{
KeySym keysym;
key_translation *tr, **prev_next;
size_t chars;
char keyname[KEYMAP_MAX_LINE_LENGTH];
/* Skip over whitespace after the sequence keyword */
chars = strspn(rest, " \t");
rest += chars;
/* Fetch the keysym name */
chars = strcspn(rest, " \t\0");
STRNCPY(keyname, rest, chars + 1);
rest += chars;
keysym = XStringToKeysym(keyname);
if (keysym == NoSymbol)
{
DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname, mapname));
return;
}
DEBUG_KBD(("Adding sequence for keysym (0x%lx, %s) -> ", keysym, keyname));
free_key_translation(keymap[keysym & KEYMAP_MASK]);
prev_next = &keymap[keysym & KEYMAP_MASK];
while (*rest)
{
/* Skip whitespace */
chars = strspn(rest, " \t");
rest += chars;
/* Fetch the keysym name */
chars = strcspn(rest, " \t\0");
STRNCPY(keyname, rest, chars + 1);
rest += chars;
keysym = XStringToKeysym(keyname);
if (keysym == NoSymbol)
{
DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname,
mapname));
return;
}
/* Allocate space for key_translation structure */
tr = (key_translation *) xmalloc(sizeof(key_translation));
memset(tr, 0, sizeof(key_translation));
*prev_next = tr;
prev_next = &tr->next;
tr->seq_keysym = keysym;
DEBUG_KBD(("0x%x, ", (unsigned int) keysym));
}
DEBUG_KBD(("\n"));
}
示例2: setupUserHomeDirectory
void setupUserHomeDirectory()
{
STRNCPY(gameSavePath, "", sizeof(gameSavePath));
STRNCPY(tempFile, "tmpsave", sizeof(tempFile));
STRNCPY(saveFileIndex, "saveheader", sizeof(saveFileIndex));
STRNCPY(continueFile, "continuesave", sizeof(continueFile));
}
示例3: formatline
int
formatline(char *line)
{
register int end;
char *temp;
int num = 0;
if (!line)
return 0;
if (strlen(line) <= MAXMACRO)
{
STRNCPY(maclines[num], line, sizeof(maclines[0]));
lineno++;
return 1;
}
temp = line;
while (1)
{
end = MAXMACRO - 1;
if (end > strlen(temp))
{
lineno++;
STRNCPY(maclines[num++], temp, sizeof(maclines[0]));
return (num);
}
else
for (; temp[end] != '%'; end--);
lineno++;
STRNCPY(maclines[num++], temp, end);
temp = temp + end;
}
}
示例4: memset
bool DialogChangePassword::ResetUserPasswordStick10(void) {
int ret;
QByteArray PasswordString;
unsigned char data[50 + 1];
memset(data, 0, sizeof(data));
// New User PIN
PasswordString = ui->lineEdit_OldPW->text().toLatin1();
STRNCPY((char *)data, 25, PasswordString.data(), 25);
// Admin PIN
PasswordString = ui->lineEdit_NewPW_1->text().toLatin1();
STRNCPY((char *)&(data[25]), 25, PasswordString.data(), 25);
ret = cryptostick->unlockUserPasswordStick10(data);
bool success = ret == CMD_STATUS_OK;
if (!success) {
if (CMD_STATUS_WRONG_PASSWORD == ret) {
csApplet->warningBox(tr("Wrong Admin PIN."));
} else {
csApplet->warningBox(tr("Couldn't unblock the user PIN. Error: %1").arg(ret));
}
} else {
csApplet->messageBox(tr("User PIN successfully unblocked"));
}
return success;
}
示例5: sup_gamedir_path
// Turns path into a full path:
// - if not absolute, prepends gamedir
// - calls realpath() to collapse ".." and such
// - calls normalize_pathname() to fix backslashes, etc
//
// Much like realpath, buffer pointed to by fullpath is assumed to be
// able to store a string of PATH_MAX length.
void sup_gamedir_path(const char *path, char *fullpath)
{
char buf[PATH_MAX];
// Build pathname from filename, plus gamedir if relative path.
if(is_absolute_path(path))
STRNCPY(buf, path, sizeof(buf));
else
{
const char *plugpath = gpMetaUtilFuncs->pfnGetPluginPath(PLID);
STRNCPY(buf, plugpath, sizeof(buf));
for(int i = strlen(buf); i != -1; i--)
{
if(buf[i] == '/')
{
buf[i + 1] = '\0';
break;
}
}
strncat(buf, path, sizeof(buf));
}
normalize_path(buf);
STRNCPY(fullpath, buf, sizeof(buf));
}
示例6: __tds__SetUser
SOAP_FMAC5 int SOAP_FMAC6 __tds__SetUser(struct soap* hSoap, struct _tds__SetUser *tds__SetUser, struct _tds__SetUserResponse *tds__SetUserResponse)
{
NEW(User,USERS);
ONVIF *Onvif = (ONVIF*)hSoap->hdOnvif;
INT i;
NEWMIII(hSoap->fault ,struct SOAP_ENV__Fault,1);
NEWMIII(hSoap->fault->SOAP_ENV__Code,struct SOAP_ENV__Code ,1);
NEWMIII(hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode,struct SOAP_ENV__Code,1);
NEWMIII(hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Subcode,struct SOAP_ENV__Code ,1);
NEWMIII(hSoap->fault->SOAP_ENV__Reason,struct SOAP_ENV__Reason,1);
if(NULL != tds__SetUser && NULL != tds__SetUser->User){
for(i=0;i<tds__SetUser->__sizeUser&&i<OVFMAXCHANNEL;i++){
STRNCPY(User->Users[i].UserName,tds__SetUser->User[i].Username,OVFCHARLENTH);;
STRNCPY(User->Users[i].UserPwd ,tds__SetUser->User[i].Password,OVFCHARLENTH);;
User->Users[i].UserLevel =tds__SetUser->User[i].UserLevel;
}
}
CHECK_CALLBACKFUC(Onvif->CallBackOvf,CallBackDevManage,SetUsers);
if(FALSE==Onvif->CallBackOvf->CallBackDevManage->SetUsers( User)){
hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Subcode->SOAP_ENV__Value ="ter:UsernameMissing" ;
hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Value ="ter:InvalidArgVal";
hSoap->fault->SOAP_ENV__Reason->SOAP_ENV__Text="The username Missing.";
return SOAP_FAULT;
}
return SOAP_OK;
}
示例7: reset
void InetAddr::set(char *straddr, int portnum)
{
reset();
inet_addr_.sin_family = AF_INET;
inet_addr_.sin_port = htons(portnum);
if (straddr != NULL) {
if (_isIPnumber(straddr)) {
inet_addr_.sin_addr.s_addr = inet_addr(straddr);
STRNCPY(ipaddr, straddr, _LEN_INADDR);
}
else {
STRNCPY(hostname, straddr, _LEN_HOSTNAME);
struct hostent *hent;
hent = gethostbyname(straddr);
if (hent==NULL) {
inet_addr_.sin_addr.s_addr = htonl(INADDR_ANY);
}
else {
memcpy(& (inet_addr_.sin_addr.s_addr), hent->h_addr, hent->h_length);
STRNCPY(ipaddr, inet_ntoa( *( (struct in_addr *) hent->h_addr ) ), _LEN_INADDR);
}
}
}
else
inet_addr_.sin_addr.s_addr = htonl(INADDR_ANY);
}
示例8: format
char *
format(char *buf, char *from, int width, int right_justify)
{
int len = strlen(from), i;
if (len > width)
len = width;
buf[width] = '\0';
if (right_justify)
{
STRNCPY(&(buf[width - len]), from, len);
for (i = 0; i < (width - len); i++)
buf[i] = ' ';
}
else
{
STRNCPY(buf, from, len);
for (i = len; i < width; i++)
buf[i] = ' ';
}
return (buf);
}
示例9: ITOA
//=============================================================================
// Return the length of the given track
//=============================================================================
int CCDAudio::GetTrackLength(const int nTrack)
{
if(IsMediaInsert())
{
const int nBuffSize = 64;
TCHAR szTrack[10];
TCHAR szReqBuff[nBuffSize];
TCHAR szBuff[nBuffSize];
ITOA( nTrack, szTrack, 10 );
lstrcpy( szReqBuff, _T("status cdaudio length track ") );
lstrcat( szReqBuff, szTrack );
m_nErrorCode = mciSendString( szReqBuff, szBuff, nBuffSize, NULL );
if( m_nErrorCode != 0 )
{
return 0;
}
TCHAR szMin[3], szSec[3];
STRNCPY( szMin, szBuff, 2 );
STRNCPY( szSec, (szBuff + 3), 2 );
return ((ATOI(szMin) * 60) + ATOI(szSec));
}
return 0;
}
示例10: switch
bool DialogChangePassword::SendNewPassword(void) {
bool communicationSuccess;
QByteArray PasswordString;
int password_length = STICK20_PASSOWRD_LEN;
unsigned char Data[password_length + 2];
// Set kind of password
switch (PasswordKind) {
case STICK20_PASSWORD_KIND_USER:
Data[0] = 'P';
break;
case STICK20_PASSWORD_KIND_ADMIN:
Data[0] = 'A';
break;
default:
Data[0] = '?';
break;
}
// Send old password
PasswordString = ui->lineEdit_OldPW->text().toLatin1();
STRNCPY((char *)&Data[1], STICK20_PASSOWRD_LEN - 1, PasswordString.data(), STICK20_PASSOWRD_LEN);
Data[STICK20_PASSOWRD_LEN + 1] = 0;
communicationSuccess = cryptostick->stick20SendPassword(Data);
if (!communicationSuccess) {
csApplet->warningBox(tr("There was a problem during communicating with device. Please retry."));
return false;
}
bool isOldPasswordCorrect = CheckResponse(TRUE) == 1;
if (!isOldPasswordCorrect) {
csApplet->warningBox(tr("Current password is not correct. Please retry."));
return false;
}
// Change password
PasswordString = ui->lineEdit_NewPW_1->text().toLatin1();
STRNCPY((char *)&Data[1], STICK20_PASSOWRD_LEN, PasswordString.data(), STICK20_PASSOWRD_LEN);
Data[STICK20_PASSOWRD_LEN + 1] = 0;
communicationSuccess = cryptostick->stick20SendNewPassword(Data);
if (!communicationSuccess) {
csApplet->warningBox(tr("There was a problem during communicating with device. Please retry."));
return false;
}
bool isNewPasswordCorrect = CheckResponse(FALSE) == 1;
if (!isNewPasswordCorrect) {
csApplet->warningBox(tr("New password is not correct. Please retry."));
return false;
}
csApplet->messageBox(tr("New password is set"));
return true;
}
示例11: loadWidgetSet
static void loadWidgetSet(char *filename)
{
cJSON *root, *node;
char *text;
Widget *w;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
text = readFile(filename);
root = cJSON_Parse(text);
for (node = root->child ; node != NULL ; node = node->next)
{
w = malloc(sizeof(Widget));
memset(w, 0, sizeof(Widget));
w->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
STRNCPY(w->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
STRNCPY(w->group, cJSON_GetObjectItem(node, "group")->valuestring, MAX_NAME_LENGTH);
w->rect.x = cJSON_GetObjectItem(node, "x")->valueint;
w->rect.y = cJSON_GetObjectItem(node, "y")->valueint;
w->rect.w = cJSON_GetObjectItem(node, "w")->valueint;
w->rect.h = cJSON_GetObjectItem(node, "h")->valueint;
w->enabled = 1;
w->visible = 1;
if (w->rect.x == -1)
{
w->rect.x = SCREEN_WIDTH / 2;
}
switch (w->type)
{
case WT_BUTTON:
STRNCPY(w->text, cJSON_GetObjectItem(node, "text")->valuestring, MAX_NAME_LENGTH);
w->rect.x -= w->rect.w / 2;
w->rect.y -= (w->rect.h / 2) + 8;
break;
case WT_SELECT:
STRNCPY(w->text, cJSON_GetObjectItem(node, "text")->valuestring, MAX_NAME_LENGTH);
w->rect.x -= w->rect.w / 2;
w->rect.y -= (w->rect.h / 2) + 8;
createOptions(w, cJSON_GetObjectItem(node, "options")->valuestring);
break;
}
tail->next = w;
tail = w;
}
cJSON_Delete(root);
free(text);
}
示例12: rxvt_update_lastlog
/* INTPROTO */
static void
rxvt_update_lastlog(const char *fname, const char *pty, const char *host)
{
# ifdef HAVE_STRUCT_LASTLOGX
struct lastlogx llx;
# endif
# ifdef HAVE_STRUCT_LASTLOG
int fd;
struct lastlog ll;
# ifdef LASTLOG_IS_DIR
char lastlogfile[256];
# endif
struct passwd *pwent;
# endif
# ifdef HAVE_STRUCT_LASTLOGX
MEMSET(&llx, 0, sizeof(llx));
llx.ll_tv.tv_sec = time(NULL);
llx.ll_tv.tv_usec = 0;
STRNCPY(llx.ll_line, pty, sizeof(llx.ll_line));
STRNCPY(llx.ll_host, host, sizeof(llx.ll_host));
updlastlogx(RXVT_LASTLOGX_FILE, getuid(), &llx);
# endif
# ifdef HAVE_STRUCT_LASTLOG
pwent = getpwuid(getuid());
if (!pwent) {
rxvt_msg (DBG_ERROR, DBG_LOGGING, "no entry in password file");
return;
}
MEMSET(&ll, 0, sizeof(ll));
ll.ll_time = time(NULL);
STRNCPY(ll.ll_line, pty, sizeof(ll.ll_line));
STRNCPY(ll.ll_host, host, sizeof(ll.ll_host));
# ifdef LASTLOG_IS_DIR
sprintf(lastlogfile, "%.*s/%.*s",
sizeof(lastlogfile) - sizeof(pwent->pw_name) - 2, fname,
sizeof(pwent->pw_name),
(!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown"
: pwent->pw_name);
if ((fd = open(lastlogfile, O_WRONLY | O_CREAT, 0644)) >= 0) {
write(fd, &ll, sizeof(ll));
close(fd);
}
# else
if ((fd = open(fname, O_RDWR)) != -1) {
if (lseek(fd, (off_t) ((long)pwent->pw_uid * sizeof(ll)),
SEEK_SET) != -1)
write(fd, &ll, sizeof(ll));
close(fd);
}
# endif /* LASTLOG_IS_DIR */
# endif /* HAVE_STRUCT_LASTLOG */
}
示例13: loadCapitalShipDef
static void loadCapitalShipDef(char *filename)
{
cJSON *root;
char *text;
Entity *e;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
text = readFile(filename);
root = cJSON_Parse(text);
if (root)
{
e = malloc(sizeof(Entity));
memset(e, 0, sizeof(Entity));
defTail->next = e;
defTail = e;
e->type = ET_CAPITAL_SHIP;
e->active = 1;
STRNCPY(e->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
STRNCPY(e->defName, e->name, MAX_NAME_LENGTH);
e->shield = e->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
e->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
e->texture = getTexture(cJSON_GetObjectItem(root, "texture")->valuestring);
e->speed = 1;
e->systemPower = 3;
e->flags = EF_NO_HEALTH_BAR;
e->action = think;
e->die = die;
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
e->separationRadius = MAX(e->w, e->h);
loadComponents(e, cJSON_GetObjectItem(root, "components"));
loadGuns(e, cJSON_GetObjectItem(root, "guns"));
loadEngines(e, cJSON_GetObjectItem(root, "engines"));
cJSON_Delete(root);
}
else
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to load '%s'", filename);
}
free(text);
}
示例14: str_handle_lines
/* Split input into lines, and call linehandler for each
line. Incomplete lines are saved in the rest variable, which should
initially point to NULL. When linehandler returns False, stop and
return False. Otherwise, return True. */
RD_BOOL
str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
{
char *buf, *p;
char *oldrest;
size_t inputlen;
size_t buflen;
size_t restlen = 0;
RD_BOOL ret = True;
/* Copy data to buffer */
inputlen = strlen(input);
if (*rest)
restlen = strlen(*rest);
buflen = restlen + inputlen + 1;
buf = (char *) xmalloc(buflen);
buf[0] = '\0';
if (*rest)
STRNCPY(buf, *rest, buflen);
strncat(buf, input, inputlen);
p = buf;
while (1)
{
char *newline = strchr(p, '\n');
if (newline)
{
*newline = '\0';
if (!linehandler(p, data))
{
p = newline + 1;
ret = False;
break;
}
p = newline + 1;
}
else
{
break;
}
}
/* Save in rest */
oldrest = *rest;
restlen = buf + buflen - p;
*rest = (char *) xmalloc(restlen);
STRNCPY((*rest), p, restlen);
xfree(oldrest);
xfree(buf);
return ret;
}
示例15: FTPInitConnectionInfo
int
FTPInitConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip, size_t bufSize)
{
size_t siz;
if ((lip == NULL) || (cip == NULL) || (bufSize == 0))
return (kErrBadParameter);
siz = sizeof(FTPConnectionInfo);
(void) memset(cip, 0, siz);
if (strcmp(lip->magic, kLibraryMagic))
return (kErrBadMagic);
cip->buf = NULL; /* denote that it needs to be allocated. */
cip->bufSize = bufSize;
cip->port = lip->defaultPort;
cip->firewallPort = lip->defaultPort;
cip->maxDials = kDefaultMaxDials;
cip->redialDelay = kDefaultRedialDelay;
cip->xferTimeout = kDefaultXferTimeout;
cip->connTimeout = kDefaultConnTimeout;
cip->ctrlTimeout = kDefaultCtrlTimeout;
cip->abortTimeout = kDefaultAbortTimeout;
cip->ctrlSocketR = kClosedFileDescriptor;
cip->ctrlSocketW = kClosedFileDescriptor;
cip->dataPortMode = kSendPortMode;
cip->dataSocket = kClosedFileDescriptor;
cip->lip = lip;
cip->hasPASV = kCommandAvailabilityUnknown;
cip->hasSIZE = kCommandAvailabilityUnknown;
cip->hasMDTM = kCommandAvailabilityUnknown;
cip->hasREST = kCommandAvailabilityUnknown;
cip->hasNLST_d = kCommandAvailabilityUnknown;
cip->hasUTIME = kCommandAvailabilityUnknown;
cip->hasFEAT = kCommandAvailabilityUnknown;
cip->hasMLSD = kCommandAvailabilityUnknown;
cip->hasMLST = kCommandAvailabilityUnknown;
cip->hasCLNT = kCommandAvailabilityUnknown;
cip->hasRETRBUFSIZE = kCommandAvailabilityUnknown;
cip->hasRBUFSIZ = kCommandAvailabilityUnknown;
cip->hasRBUFSZ = kCommandAvailabilityUnknown;
cip->hasSTORBUFSIZE = kCommandAvailabilityUnknown;
cip->hasSBUFSIZ = kCommandAvailabilityUnknown;
cip->hasSBUFSZ = kCommandAvailabilityUnknown;
cip->STATfileParamWorks = kCommandAvailabilityUnknown;
cip->NLSTfileParamWorks = kCommandAvailabilityUnknown;
cip->firewallType = kFirewallNotInUse;
cip->startingWorkingDirectory = NULL;
(void) STRNCPY(cip->magic, kLibraryMagic);
(void) STRNCPY(cip->user, "anonymous");
return (kNoErr);
} /* FTPInitConnectionInfo */