本文整理汇总了C++中StrnCpy函数的典型用法代码示例。如果您正苦于以下问题:C++ StrnCpy函数的具体用法?C++ StrnCpy怎么用?C++ StrnCpy使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StrnCpy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strlen
/****************************************************************************
an enhanced crypt for OSF1
****************************************************************************/
static char *osf1_bigcrypt(char *password, char *salt1)
{
static char result[AUTH_MAX_PASSWD_LENGTH] = "";
char *p1;
char *p2 = password;
char salt[3];
int i;
int parts = strlen(password) / AUTH_CLEARTEXT_SEG_CHARS;
if (strlen(password) % AUTH_CLEARTEXT_SEG_CHARS)
parts++;
StrnCpy(salt, salt1, 2);
StrnCpy(result, salt1, 2);
result[2] = '\0';
for (i = 0; i < parts; i++) {
p1 = crypt(p2, salt);
strncat(result, p1 + 2,
AUTH_MAX_PASSWD_LENGTH - strlen(p1 + 2) - 1);
StrnCpy(salt, &result[2 + i * AUTH_CIPHERTEXT_SEG_CHARS], 2);
p2 += AUTH_CLEARTEXT_SEG_CHARS;
}
return (result);
}
示例2: fill_share_2
void fill_share_2(SHARE_INFO_1 *sh1, int snum)
{
StrnCpy(sh1[0].shi1_netname, "tmp", 13);
sh1[0].shi1_type = STYPE_DISKTREE;
sh1[0].shi1_remark = "some weird comment";
lp_comment(snum);
lp_pathname(snum);
StrnCpy(p, lp_servicename(snum), 13);
type = STYPE_DISKTREE;
if (lp_print_ok(snum))
type = STYPE_PRINTQ;
if (strequal("IPC$", lp_servicename(snum)))
type = STYPE_IPC;
lp_comment(snum);
#endif
void fill_share_1(SHARE_INFO_1 *sh1, int snum)
{
StrnCpy(sh1->shi1_netname, lp_servicename(snum), 13);
sh1->shi1_remark = lp_comment(snum);
sh1->shi1_type = STYPE_DISKTREE;
if (lp_print_ok(snum))
sh1->shi1_type = STYPE_PRINTQ;
if (strequal("IPC$", lp_servicename(snum)))
sh1->shi1_type = STYPE_IPC;
}
示例3: SNUM
/****************************************************************************
Build the print command in the supplied buffer. This means getting the
print command for the service and inserting the printer name and the
print file name. Return NULL on error, else the passed buffer pointer.
****************************************************************************/
static char *build_print_command(int cnum, char *command, char *syscmd, char *filename1)
{
int snum = SNUM(cnum);
char *tstr;
pstring filename;
/* get the print command for the service. */
tstr = command;
if (!syscmd || !tstr) {
DEBUG(0,("No print command for service `%s'\n", SERVICE(snum)));
return (NULL);
}
/* copy the command into the buffer for extensive meddling. */
StrnCpy(syscmd, tstr, sizeof(pstring) - 1);
/* look for "%s" in the string. If there is no %s, we cannot print. */
if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f")) {
DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum)));
}
if (strstr(syscmd,"%s")) {
int iOffset = PTR_DIFF(strstr(syscmd, "%s"),syscmd);
/* construct the full path for the filename, shouldn't be necessary unless
the subshell causes a "cd" to be executed.
Only use the full path if there isn't a / preceding the %s */
if (iOffset==0 || syscmd[iOffset-1] != '/') {
StrnCpy(filename,Connections[cnum].connectpath,sizeof(filename)-1);
trim_string(filename,"","/");
pstrcat(filename,"/");
pstrcat(filename,filename1);
}
else
pstrcpy(filename,filename1);
string_sub(syscmd, "%s", filename);
}
string_sub(syscmd, "%f", filename1);
/* Does the service have a printername? If not, make a fake and empty */
/* printer name. That way a %p is treated sanely if no printer */
/* name was specified to replace it. This eventuality is logged. */
tstr = PRINTERNAME(snum);
if (tstr == NULL || tstr[0] == '\0') {
DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum)));
tstr = SERVICE(snum);
}
string_sub(syscmd, "%p", tstr);
standard_sub(cnum,syscmd);
return (syscmd);
}
示例4: Printing
/****************************************************************************
parse a lpq line for the plp printing system
Bertrand Wallrich <[email protected]>
redone by tridge. Here is a sample queue:
Local Printer 'lp2' (fjall):
Printing (started at Jun 15 13:33:58, attempt 1).
Rank Owner Pr Opt Job Host Files Size Date
active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
****************************************************************************/
static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first)
{
fstring tok[11];
int count=0;
/* handle the case of "(standard input)" as a filename */
string_sub(line,"stdin","STDIN");
string_sub(line,"(","\"");
string_sub(line,")","\"");
for (count=0; count<11 && next_token(&line,tok[count],NULL); count++) ;
/* we must get 11 tokens */
if (count < 11)
return(False);
/* the first must be "active" or begin with an integer */
if (strcmp(tok[0],"active") && !isdigit(tok[0][0]))
return(False);
/* the 5th and 8th must be integer */
if (!isdigit(*tok[4]) || !isdigit(*tok[7]))
return(False);
/* if the fname contains a space then use STDIN */
if (strchr(tok[6],' '))
fstrcpy(tok[6],"STDIN");
/* only take the last part of the filename */
{
fstring tmp;
char *p = strrchr(tok[6],'/');
if (p)
{
fstrcpy(tmp,p+1);
fstrcpy(tok[6],tmp);
}
}
buf->job = atoi(tok[4]);
buf->size = atoi(tok[7]);
if (strchr(tok[7],'K'))
buf->size *= 1024;
if (strchr(tok[7],'M'))
buf->size *= 1024*1024;
buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
buf->priority = 0;
buf->time = time(NULL);
StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
return(True);
}
示例5: parse_lpq_qnx
/****************************************************************************
parse a lpq line
here is an example of lpq output under qnx
Spooler: /qnx/spooler, on node 1
Printer: txt (ready)
0000: root [job #1 ] active 1146 bytes /etc/profile
0001: root [job #2 ] ready 2378 bytes /etc/install
0002: root [job #3 ] ready 1146 bytes -- standard input --
****************************************************************************/
static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first)
{
fstring tok[7];
int count=0;
DEBUG(0,("antes [%s]\n", line));
/* handle the case of "-- standard input --" as a filename */
string_sub(line,"standard input","STDIN");
DEBUG(0,("despues [%s]\n", line));
string_sub(line,"-- ","\"");
string_sub(line," --","\"");
DEBUG(0,("despues 1 [%s]\n", line));
string_sub(line,"[job #","");
string_sub(line,"]","");
DEBUG(0,("despues 2 [%s]\n", line));
for (count=0; count<7 && next_token(&line,tok[count],NULL); count++) ;
/* we must get 7 tokens */
if (count < 7)
return(False);
/* the 3rd and 5th columns must be integer */
if (!isdigit(*tok[2]) || !isdigit(*tok[4])) return(False);
/* only take the last part of the filename */
{
fstring tmp;
char *p = strrchr(tok[6],'/');
if (p)
{
fstrcpy(tmp,p+1);
fstrcpy(tok[6],tmp);
}
}
buf->job = atoi(tok[2]);
buf->size = atoi(tok[4]);
buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
buf->priority = 0;
buf->time = time(NULL);
StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
return(True);
}
示例6: _interpret_node_status
/****************************************************************************
interpret a node status response
****************************************************************************/
static void _interpret_node_status(char *p, char *master,char *rname)
{
int numnames = CVAL(p,0);
DEBUG(1,("received %d names\n",numnames));
if (rname) *rname = 0;
if (master) *master = 0;
p += 1;
while (numnames--)
{
char qname[17];
int type;
fstring flags;
int i;
*flags = 0;
StrnCpy(qname,p,15);
type = CVAL(p,15);
p += 16;
fstrcat(flags, (p[0] & 0x80) ? "<GROUP> " : " ");
if ((p[0] & 0x60) == 0x00) fstrcat(flags,"B ");
if ((p[0] & 0x60) == 0x20) fstrcat(flags,"P ");
if ((p[0] & 0x60) == 0x40) fstrcat(flags,"M ");
if ((p[0] & 0x60) == 0x60) fstrcat(flags,"H ");
if (p[0] & 0x10) fstrcat(flags,"<DEREGISTERING> ");
if (p[0] & 0x08) fstrcat(flags,"<CONFLICT> ");
if (p[0] & 0x04) fstrcat(flags,"<ACTIVE> ");
if (p[0] & 0x02) fstrcat(flags,"<PERMANENT> ");
if (master && !*master && type == 0x1d) {
StrnCpy(master,qname,15);
trim_string(master,NULL," ");
}
if (rname && !*rname && type == 0x20 && !(p[0]&0x80)) {
StrnCpy(rname,qname,15);
trim_string(rname,NULL," ");
}
for (i = strlen( qname) ; --i >= 0 ; ) {
if (!isprint((int)qname[i])) qname[i] = '.';
}
DEBUG(1,("\t%-15s <%02x> - %s\n",qname,type,flags));
p+=2;
}
DEBUG(1,("num_good_sends=%d num_good_receives=%d\n",
IVAL(p,20),IVAL(p,24)));
}
示例7: CreateFullDestPath
/**
Function to take the destination path and target file name to generate the full destination path.
@param[in] DestPath A pointer to the destination file path string.
@param[out] FullDestPath A pointer to the full destination path string.
@param[in] FileName Name string of the targe file.
@retval SHELL_SUCCESS the files were all moved.
@retval SHELL_INVALID_PARAMETER a parameter was invalid
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
EFI_STATUS
EFIAPI
CreateFullDestPath(
IN CONST CHAR16 **DestPath,
OUT CHAR16 **FullDestPath,
IN CONST CHAR16 *FileName
)
{
UINTN Size;
if (FullDestPath == NULL || FileName == NULL || DestPath == NULL || *DestPath == NULL){
return (EFI_INVALID_PARAMETER);
}
Size = StrSize(*DestPath) + StrSize(FileName);
*FullDestPath = AllocateZeroPool(Size);
if (*FullDestPath == NULL){
return (EFI_OUT_OF_RESOURCES);
}
StrnCpy(*FullDestPath, *DestPath, Size / sizeof(CHAR16) - 1);
if ((*FullDestPath)[StrLen(*FullDestPath)-1] != L'\\' && FileName[0] != L'\\') {
StrnCat(*FullDestPath, L"\\",Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));
}
StrnCat(*FullDestPath, FileName, Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));
return (EFI_SUCCESS);
}
示例8: FatHashLongName
STATIC
UINT32
FatHashLongName (
IN CHAR16 *LongNameString
)
/*++
Routine Description:
Get hash value for long name.
Arguments:
LongNameString - The long name string to be hashed.
Returns:
HashValue.
--*/
{
UINT32 HashValue;
CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];
StrnCpy (UpCasedLongFileName, LongNameString, EFI_PATH_STRING_LENGTH - 1);
UpCasedLongFileName[EFI_PATH_STRING_LENGTH - 1] = L'\0';
FatStrUpr (UpCasedLongFileName);
gBS->CalculateCrc32 (UpCasedLongFileName, StrSize (UpCasedLongFileName), &HashValue);
return (HashValue & HASH_TABLE_MASK);
}
示例9: HashVal
Var *FindVar(char const *str, int create)
{
register int h;
register Var *v;
register Var *prev;
h = HashVal(str) % VAR_HASH_SIZE;
v = VHashTbl[h];
prev = NULL;
while(v) {
if (! StrinCmp(str, v->name, VAR_NAME_LEN)) return v;
prev = v;
v = v-> next;
}
if (!create) return v;
/* Create the variable */
v = NEW(Var);
if (!v) return v;
v->next = NULL;
v->v.type = INT_TYPE;
v->v.v.val = 0;
v->preserve = 0;
StrnCpy(v->name, str, VAR_NAME_LEN);
if (prev) prev->next = v; else VHashTbl[h] = v;
return v;
}
示例10: _api_DosNetServerGetInfo
uint16 _api_DosNetServerGetInfo(PCONN_HND phnd, io_struct * ps,
uint16 sLevel,
RCVBUF pbBuffer,
RCVBUFLEN cbBuffer, uint16 *pcTotalAvail)
{
SERVER_INFO_1 sv1;
DEBUG(10,("DosNetServerGetInfo: %d buf %d\n",
sLevel, cbBuffer));
StrnCpy(sv1.sv1_name, local_machine, 16);
strupper(sv1.sv1_name);
sv1.sv1_version_major = 4;
sv1.sv1_version_minor = 1;
sv1.sv1_type = SV_TYPE_NT;
sv1.sv1_comment_or_master_browser = string_truncate(lp_serverstring(),
MAX_SERVER_STRING_LENGTH);
switch (sLevel)
{
case 1:
{
if (!io_SERVER_INFO_1("sv1", ps, 0, &sv1,
PARSE_SCALARS))
return NERR_BufTooSmall;
if (!io_SERVER_INFO_1("sv1", ps, 0, &sv1,
PARSE_OFFSETS))
return NERR_BufTooSmall;
return ERRsuccess;
}
}
return ERRunknownlevel;
}
示例11: client_name
/*******************************************************************
return the DNS name of the client
******************************************************************/
char *
client_name (int fd)
{
struct sockaddr sa;
struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
unsigned int length = sizeof (sa);
static pstring name_buf;
struct hostent *hp;
static int last_fd = -1;
if (global_client_name_done && last_fd == fd)
return name_buf;
last_fd = fd;
global_client_name_done = False;
pstrcpy (name_buf, "UNKNOWN");
if (fd == -1)
{
return name_buf;
}
if (getpeername (fd, &sa, &length) < 0)
{
DEBUG (0, ("getpeername failed. Error was %s\n", unix_error_string (errno)));
return name_buf;
}
/* Look up the remote host name. */
if ((hp = gethostbyaddr ((char *) &sockin->sin_addr, sizeof (sockin->sin_addr), AF_INET)) == 0)
{
DEBUG (1, ("Gethostbyaddr failed for %s\n", client_addr (fd)));
StrnCpy (name_buf, client_addr (fd), sizeof (name_buf) - 1);
}
else
{
StrnCpy (name_buf, (char *) hp->h_name, sizeof (name_buf) - 1);
if (!matchname (name_buf, sockin->sin_addr))
{
DEBUG (0, ("Matchname failed on %s %s\n", name_buf, client_addr (fd)));
pstrcpy (name_buf, "UNKNOWN");
}
}
global_client_name_done = True;
return name_buf;
}
示例12: SetEnvironmentVariables
/**
sets a list of all Shell-Guid-based environment variables.
@param Environment Points to a NULL-terminated array of environment
variables with the format 'x=y', where x is the
environment variable name and y is the value.
@retval EFI_SUCCESS The command executed successfully.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@sa SetEnvironmentVariableList
**/
EFI_STATUS
EFIAPI
SetEnvironmentVariables(
IN CONST CHAR16 **Environment
)
{
CONST CHAR16 *CurrentString;
UINTN CurrentCount;
ENV_VAR_LIST *VarList;
ENV_VAR_LIST *Node;
UINTN NewSize;
VarList = NULL;
if (Environment == NULL) {
return (EFI_INVALID_PARAMETER);
}
//
// Build a list identical to the ones used for get/set list functions above
//
for ( CurrentCount = 0
;
; CurrentCount++
) {
CurrentString = Environment[CurrentCount];
if (CurrentString == NULL) {
break;
}
ASSERT(StrStr(CurrentString, L"=") != NULL);
Node = AllocateZeroPool(sizeof(ENV_VAR_LIST));
ASSERT(Node != NULL);
Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16));
ASSERT(Node->Key != NULL);
StrnCpy(Node->Key, CurrentString, StrStr(CurrentString, L"=") - CurrentString);
NewSize = StrSize(CurrentString);
NewSize -= StrLen(Node->Key) - 1;
Node->Val = AllocateZeroPool(NewSize);
ASSERT(Node->Val != NULL);
StrCpy(Node->Val, CurrentString + StrLen(Node->Key) + 1);
Node->Atts = EFI_VARIABLE_BOOTSERVICE_ACCESS;
if (VarList == NULL) {
VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
ASSERT(VarList != NULL);
InitializeListHead(&VarList->Link);
}
InsertTailList(&VarList->Link, &Node->Link);
} // for loop
//
// set this new list as the set of all environment variables.
// this function also frees the memory and deletes all pre-existing
// shell-guid based environment variables.
//
return (SetEnvironmentVariableList(&VarList->Link));
}
示例13: lp_usernamelevel
struct passwd *Get_Pwnam(char *user,BOOL allow_change)
{
fstring user2;
int last_char;
int usernamelevel = lp_usernamelevel();
struct passwd *ret;
if (!user || !(*user))
return(NULL);
StrnCpy(user2,user,sizeof(user2)-1);
if (!allow_change) {
user = &user2[0];
}
ret = _Get_Pwnam(user);
if (ret)
return(ret);
strlower(user);
ret = _Get_Pwnam(user);
if (ret)
return(ret);
strupper(user);
ret = _Get_Pwnam(user);
if (ret)
return(ret);
/* Try with first letter capitalised. */
if (strlen(user) > 1)
strlower(user+1);
ret = _Get_Pwnam(user);
if (ret)
return(ret);
/* try with last letter capitalised */
strlower(user);
last_char = strlen(user)-1;
user[last_char] = toupper(user[last_char]);
ret = _Get_Pwnam(user);
if (ret)
return(ret);
/* Try all combinations up to usernamelevel. */
strlower(user);
ret = uname_string_combinations(user, _Get_Pwnam, usernamelevel);
if (ret)
return(ret);
if (allow_change)
fstrcpy(user,user2);
return(NULL);
}
示例14: fixtarname
static void fixtarname(char *tptr, const char *fp, size_t l)
{
/* add a '.' to start of file name, convert from ugly dos \'s in path
* to lovely unix /'s :-} */
*tptr++='.';
l--;
StrnCpy(tptr, fp, l-1);
string_replace(tptr, '\\', '/');
}
示例15: GenerateDeviceDescriptionName
EFI_STATUS
GenerateDeviceDescriptionName (
IN EFI_HANDLE Handle,
IN OUT CHAR16* Description
)
{
EFI_STATUS Status;
EFI_COMPONENT_NAME_PROTOCOL* ComponentName2Protocol;
EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
EFI_DEVICE_PATH_PROTOCOL* DevicePathProtocol;
CHAR16* DriverName;
CHAR16* DevicePathTxt;
EFI_DEVICE_PATH* DevicePathNode;
ComponentName2Protocol = NULL;
Status = gBS->HandleProtocol (Handle, &gEfiComponentName2ProtocolGuid, (VOID **)&ComponentName2Protocol);
if (!EFI_ERROR(Status)) {
//TODO: Fixme. we must find the best langague
Status = ComponentName2Protocol->GetDriverName (ComponentName2Protocol,"en",&DriverName);
if (!EFI_ERROR(Status)) {
StrnCpy (Description, DriverName, BOOT_DEVICE_DESCRIPTION_MAX);
}
}
if (EFI_ERROR(Status)) {
// Use the lastest non null entry of the Device path as a description
Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);
if (EFI_ERROR(Status)) {
return Status;
}
// Convert the last non end-type Device Path Node in text for the description
DevicePathNode = GetLastDevicePathNode (DevicePathProtocol);
Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
ASSERT_EFI_ERROR(Status);
DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePathNode, TRUE, TRUE);
StrnCpy (Description, DevicePathTxt, BOOT_DEVICE_DESCRIPTION_MAX);
FreePool (DevicePathTxt);
}
return EFI_SUCCESS;
}