本文整理汇总了C++中bu_strlcpy函数的典型用法代码示例。如果您正苦于以下问题:C++ bu_strlcpy函数的具体用法?C++ bu_strlcpy怎么用?C++ bu_strlcpy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bu_strlcpy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_Lgts
/*
Set certain default lighting info.
*/
static void
init_Lgts(void)
{
/* Ambient lighting. */
bu_strlcpy(lgts[0].name, "EYE", sizeof(lgts[0].name));
lgts[0].beam = 0;
lgts[0].over = 0;
lgts[0].rgb[0] = 255;
lgts[0].rgb[1] = 255;
lgts[0].rgb[2] = 255;
lgts[0].azim = 30.0/RAD2DEG;
lgts[0].elev = 30.0/RAD2DEG;
lgts[0].dist = 0.0;
lgts[0].energy = 0.4;
lgts[0].stp = SOLTAB_NULL;
/* Primary lighting. */
bu_strlcpy(lgts[1].name, "LIGHT", sizeof(lgts[1].name));
lgts[1].beam = 0;
lgts[1].over = 1;
lgts[1].rgb[0] = 255;
lgts[1].rgb[1] = 255;
lgts[1].rgb[2] = 255;
lgts[1].azim = 60.0/RAD2DEG;
lgts[1].elev = 60.0/RAD2DEG;
lgts[1].dist = 10000.0;
lgts[1].energy = 1.0;
lgts[1].stp = SOLTAB_NULL;
lgt_db_size = 2;
return;
}
示例2: bu_realpath
char *
bu_realpath(const char *path, char *resolved_path)
{
if (!resolved_path)
resolved_path = (char *) bu_calloc(MAXPATHLEN, sizeof(char), "resolved_path alloc");
#if defined(HAVE_WORKING_REALPATH_FUNCTION)
{
char *dirpath = NULL;
dirpath = realpath(path, resolved_path);
if (!dirpath) {
/* if path lookup failed, resort to simple copy */
bu_strlcpy(resolved_path, path, (size_t)MAXPATHLEN);
}
}
#elif defined(HAVE_GETFULLPATHNAME)
/* Best solution currently available for Windows
* See https://www.securecoding.cert.org/confluence/display/seccode/FIO02-C.+Canonicalize+path+names+originating+from+untrusted+sources */
GetFullPathName(path, MAXPATHLEN, resolved_path, NULL);
#else
/* Last resort - if NOTHING is defined, do a simple copy */
bu_strlcpy(resolved_path, path, (size_t)MAXPATHLEN);
#endif
return resolved_path;
}
示例3: get_large_field_input
HIDDEN void
get_large_field_input(FILE *fp, int write_flag)
{
char **tmp_rec;
int field_no;
int card_len;
int last_field;
int i;
tmp_rec = prev_rec;
prev_rec = curr_rec;
curr_rec = tmp_rec;
for ( field_no=0; field_no < NO_OF_FIELDS; field_no ++ )
curr_rec[field_no][0] = '\0';
card_len = strlen( line );
last_field = (card_len - 8)/16 + 1;
if ( ((last_field - 1) * 16 + 8) < card_len )
last_field++;
if ( last_field > 5 )
last_field = 5;
bu_strlcpy( curr_rec[0], line, 8 );
curr_rec[0][8] = '\0';
for ( field_no=1; field_no < last_field; field_no++ )
{
bu_strlcpy( curr_rec[field_no], &line[field_no*16 - 8], 16 );
curr_rec[field_no][16] = '\0';
}
/* remove the newline from the end of the last field */
i = strlen( curr_rec[last_field-1] ) - 1;
while ( isspace( curr_rec[last_field-1][i] ) || curr_rec[last_field-1][i] == '\012' || curr_rec[last_field-1][i] == '\015' )
i--;
curr_rec[last_field-1][++i] = '\0';
if ( next_line[0] == '*' )
{
if ( !get_next_record( fp, 0, 0 ) )
{
bu_exit(1, "unexpected end of INPUT at line #%d\n", line_count );
}
card_len = strlen( line );
last_field = (card_len - 8)/16 + 1;
if ( ((last_field - 1) * 16 + 8) < card_len )
last_field++;
if ( last_field > 5 )
last_field = 5;
last_field += 4;
for ( field_no=5; field_no < last_field; field_no++ )
{
bu_strlcpy( curr_rec[field_no], &line[(field_no-4)*16 - 8], 16 );
curr_rec[field_no][16] = '\0';
}
}
if ( write_flag )
write_fields();
}
示例4: do_silly_nastran_shortcuts
HIDDEN void
do_silly_nastran_shortcuts(void)
{
int field_no;
for (field_no=0; field_no < NO_OF_FIELDS; field_no++) {
if (BU_STR_EQUAL(curr_rec[field_no], "=")) {
bu_strlcpy(curr_rec[field_no], prev_rec[field_no], FIELD_LENGTH);
} else if (BU_STR_EQUAL(curr_rec[field_no], "==")) {
while (field_no < NO_OF_FIELDS) {
bu_strlcpy(curr_rec[field_no], prev_rec[field_no], FIELD_LENGTH);
field_no++;
}
} else if (curr_rec[field_no][0] == '*') {
int i=0;
while (curr_rec[field_no][++i] == '(');
if (strchr(prev_rec[field_no], '.')) {
fastf_t a, b;
a = atof(prev_rec[field_no]);
b = atof(&curr_rec[field_no][i]);
sprintf(curr_rec[field_no], "%-#*E", FIELD_LENGTH-6, a+b);
} else {
int a, b;
a = atoi(prev_rec[field_no]);
b = atoi(&curr_rec[field_no][i]);
sprintf(curr_rec[field_no], "%d", a+b);
}
}
}
}
示例5: nirt_units
void
nirt_units(char *buffer, com_table *ctp, struct rt_i *rtip)
{
double tmp_dbl;
int i = 0; /* current position on the *buffer */
double mk_cvt_factor();
while (isspace((int)*(buffer+i)))
++i;
if (*(buffer+i) == '\0') {
/* display current destination */
fprintf(stdout, "units = '%s'\n", local_u_name);
return;
}
if (BU_STR_EQUAL(buffer + i, "?")) {
com_usage(ctp);
return;
} else if (BU_STR_EQUAL(buffer + i, "default")) {
base2local = rtip->rti_dbip->dbi_base2local;
local2base = rtip->rti_dbip->dbi_local2base;
bu_strlcpy(local_u_name, bu_units_string(base2local), sizeof(local_u_name));
} else {
tmp_dbl = bu_units_conversion(buffer + i);
if (tmp_dbl <= 0.0) {
bu_log("Invalid unit specification: '%s'\n", buffer + i);
return;
}
bu_strlcpy(local_u_name, buffer + i, sizeof(local_u_name));
local2base = tmp_dbl;
base2local = 1.0 / tmp_dbl;
}
}
示例6: get_small_field_input
HIDDEN void
get_small_field_input(FILE *fp, int write_flag)
{
char **tmp_rec;
int field_no;
int card_len;
int last_field;
tmp_rec = prev_rec;
prev_rec = curr_rec;
curr_rec = tmp_rec;
for ( field_no=0; field_no < NO_OF_FIELDS; field_no ++ )
curr_rec[field_no][0] = '\0';
card_len = strlen( line );
last_field = card_len/8 + 1;
if ( (last_field * 8) < card_len )
last_field++;
if ( last_field > 9 )
last_field = 9;
bu_strlcpy( curr_rec[0], line, 8 );
curr_rec[0][8] = '\0';
for ( field_no=2; field_no < last_field+1; field_no++ )
{
bu_strlcpy( curr_rec[field_no-1], &line[(field_no-1)*8], 8 );
curr_rec[field_no-1][8] = '\0';
}
if ( next_line[0] == '+' )
{
if ( !get_next_record( fp, 0, 0 ) )
{
bu_exit(1, "unexpected end of INPUT at line #%d\n", line_count );
}
card_len = strlen( line );
last_field = card_len/8 + 1;
if ( (last_field * 8) < card_len )
last_field++;
if ( last_field > 9 )
last_field = 9;
last_field += 9;
for ( field_no=10; field_no < last_field+1; field_no++ )
{
bu_strlcpy( curr_rec[field_no-1], &line[(field_no-9)*8], 8 );
curr_rec[field_no-1][8] = '\0';
}
}
if ( write_flag )
write_fields();
}
示例7: main
int
main(int argc, char **argv)
{
int c = 0;
int in_num = 0;
int format = 0; /* 0 = XML, 1 = HTML */
int list = 0;
char outfile[MAXPATHLEN] = "attributes.xml";
char xref_id[MAXPATHLEN] = "auto_attributes";
const char *usage_str = "[-o output file] [-x xref id] [-f format number (0 = XML, 1 = HTML)] [-l]";
while ((c=bu_getopt(argc, argv, "f:lo:x:")) != -1) {
switch (c) {
case 'o' :
memset(outfile, 0, MAXPATHLEN);
bu_strlcpy(outfile, bu_optarg, MAXPATHLEN);
break;
case 'x' :
memset(xref_id, 0, MAXPATHLEN);
bu_strlcpy(xref_id, bu_optarg, MAXPATHLEN);
break;
case 'f' :
sscanf(bu_optarg, "%d", &in_num);
format = in_num;
break;
case 'l' :
list = 1;
break;
default:
bu_log("%s: %s\n", argv[0], usage_str);
return -1;
}
}
switch (format) {
case 0:
if (list) {
gen_attr_xml_list(outfile, xref_id);
} else {
gen_attr_xml_table(outfile, xref_id);
}
break;
case 1:
break;
default:
bu_log("Error - unknown format %d\n", format);
return -1;
}
return 0;
}
示例8: X_fb_open
void
X_fb_open(void)
{
char *X_name = "/dev/X";
if ((fbp = (FBIO *)calloc(sizeof(FBIO), 1)) == FBIO_NULL) {
Tcl_AppendResult(interp, "X_dm_init: failed to allocate framebuffer memory\n",
(char *)NULL);
return;
}
*fbp = X24_interface; /* struct copy */
fbp->if_name = bu_malloc((unsigned)strlen(X_name)+1, "if_name");
bu_strlcpy(fbp->if_name, X_name, strlen(X_name)+1);
/* Mark OK by filling in magic number */
fbp->if_magic = FB_MAGIC;
_X24_open_existing(fbp,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy,
((struct x_vars *)dmp->dm_vars.priv_vars)->pix,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->win,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->cmap,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->vip,
dmp->dm_width, dmp->dm_height,
((struct x_vars *)dmp->dm_vars.priv_vars)->gc);
}
示例9: automatic_test
/* Test against basename UNIX tool */
void
automatic_test(const char *input)
{
char buf_input[1000];
char *ans = NULL;
char *res = (char *)bu_calloc(strlen(buf_input), sizeof(char), "automatic_test res");
#ifdef HAVE_BASENAME
if (input)
bu_strlcpy(buf_input, input, strlen(input)+1);
/* build UNIX 'basename' command */
if (!input)
ans = basename(NULL);
else
ans = basename(buf_input);
if (!input)
bu_basename(res, NULL);
else
bu_basename(res, buf_input);
if (BU_STR_EQUAL(res, ans))
printf("%24s -> %24s [PASSED]\n", input, res);
else
bu_exit(EXIT_FAILURE, "%24s -> %24s (should be: %s) [FAIL]\n", input, res, ans);
bu_free(res, NULL);
#else
printf("BASENAME not available on this platform\n");
#endif
/* FIXME: this does not functionally halt */
}
示例10: icv_guess_file_format
/*
* Attempt to guess the file type. Understands ImageMagick style
* FMT:filename as being preferred, but will attempt to guess based on
* extension as well.
*
* I suck. I'll fix this later. Honest.
*
* FIXME: assuming trimmedname is BUFSIZ is a crash waiting to bite
* someone down the road. should pass a size or use a vls or have it
* return the string as as return type (making the int type be an int*
* argument instead that gets set).
*/
ICV_IMAGE_FORMAT
icv_guess_file_format(const char *filename, char *trimmedname)
{
/* look for the FMT: header */
#define CMP(name) if (!bu_strncmp(filename, #name":", strlen(#name))) {bu_strlcpy(trimmedname, filename+strlen(#name)+1, BUFSIZ);return ICV_IMAGE_##name; }
CMP(PIX);
CMP(PNG);
CMP(PPM);
CMP(BMP);
CMP(BW);
CMP(DPIX)
#undef CMP
/* no format header found, copy the name as it is */
bu_strlcpy(trimmedname, filename, BUFSIZ);
/* and guess based on extension */
#define CMP(name, ext) if (!bu_strncmp(filename+strlen(filename)-strlen(#name)-1, "."#ext, strlen(#name)+1)) return ICV_IMAGE_##name;
CMP(PIX, pix);
CMP(PNG, png);
CMP(PPM, ppm);
CMP(BMP, bmp);
CMP(BW, bw);
CMP(DPIX, dpix);
#undef CMP
/* defaulting to PIX */
return ICV_IMAGE_UNKNOWN;
}
示例11: Wgl_fb_open
void
Wgl_fb_open()
{
char *wgl_name = "/dev/wgl";
if ((fbp = (FBIO *)calloc(sizeof(FBIO), 1)) == FBIO_NULL) {
Tcl_AppendResult(interp, "Wgl_fb_open: failed to allocate framebuffer memory\n",
(char *)NULL);
return;
}
*fbp = wgl_interface; /* struct copy */
fbp->if_name = bu_malloc((unsigned)strlen(wgl_name)+1, "if_name");
bu_strlcpy(fbp->if_name, wgl_name, strlen(wgl_name)+1);
/* Mark OK by filling in magic number */
fbp->if_magic = FB_MAGIC;
_wgl_open_existing(fbp,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->win,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->cmap,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->vip,
((struct dm_xvars *)dmp->dm_vars.pub_vars)->hdc,
dmp->dm_width, dmp->dm_height,
((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc,
((struct wgl_vars *)dmp->dm_vars.priv_vars)->mvars.doublebuffer, 0);
}
示例12: rt_vlist_export
void
rt_vlist_export(struct bu_vls *vls, struct bu_list *hp, const char *name)
{
register struct bn_vlist *vp;
size_t nelem;
size_t namelen;
size_t nbytes;
unsigned char *buf;
unsigned char *bp;
BU_CK_VLS(vls);
/* Count number of element in the vlist */
nelem = 0;
for (BU_LIST_FOR(vp, bn_vlist, hp)) {
nelem += vp->nused;
}
/* Build output buffer for binary transmission
* nelem[4], String[n+1], cmds[nelem*1], pts[3*nelem*8]
*/
namelen = strlen(name)+1;
nbytes = namelen + 4 + nelem * (1+ELEMENTS_PER_VECT*SIZEOF_NETWORK_DOUBLE) + 2;
/* FIXME: this is pretty much an abuse of vls. should be using
* vlb for variable-length byte buffers.
*/
bu_vls_setlen(vls, (int)nbytes);
buf = (unsigned char *)bu_vls_addr(vls);
*(uint32_t *)buf = htonl((uint32_t)nelem);
bp = buf+sizeof(uint32_t);
bu_strlcpy((char *)bp, name, namelen);
bp += namelen;
/* Output cmds, as bytes */
for (BU_LIST_FOR(vp, bn_vlist, hp)) {
register int i;
register int nused = vp->nused;
register int *cmd = vp->cmd;
for (i = 0; i < nused; i++) {
*bp++ = *cmd++;
}
}
/* Output points, as three 8-byte doubles */
for (BU_LIST_FOR(vp, bn_vlist, hp)) {
register int i;
register int nused = vp->nused;
register point_t *pt = vp->pt;
/* must be double for import and export */
double point[ELEMENTS_PER_POINT];
for (i = 0; i < nused; i++) {
VMOVE(point, pt[i]); /* convert fastf_t to double */
htond(bp, (unsigned char *)point, ELEMENTS_PER_VECT);
bp += ELEMENTS_PER_VECT*SIZEOF_NETWORK_DOUBLE;
}
}
}
示例13: rt_dirbuild
/**
* Builds a directory of the object names.
*
* Allocate and initialize information for this instance of an RT
* model database.
*
* Returns -
* (struct rt_i *) Success
* RTI_NULL Fatal Error
*/
struct rt_i *
rt_dirbuild(const char *filename, char *buf, int len)
{
register struct rt_i *rtip;
register struct db_i *dbip; /* Database instance ptr */
if (rt_uniresource.re_magic == 0)
rt_init_resource(&rt_uniresource, 0, NULL);
if ((dbip = db_open(filename, DB_OPEN_READONLY)) == DBI_NULL)
return RTI_NULL; /* FAIL */
RT_CK_DBI(dbip);
if (db_dirbuild(dbip) < 0) {
db_close(dbip);
return RTI_NULL; /* FAIL */
}
rtip = rt_new_rti(dbip); /* clones dbip */
db_close(dbip); /* releases original dbip */
if (buf != (char *)NULL)
bu_strlcpy(buf, dbip->dbi_title, len);
return rtip; /* OK */
}
示例14: basename_without_suffix
/**
* Return basename of path, removing leading slashes and trailing suffix.
*/
static char *
basename_without_suffix(const char *p1, const char *suff)
{
char *p2, *p3;
static char buf[128];
/* find the basename */
p2 = (char *)p1;
while (*p1) {
if (*p1++ == '/')
p2 = (char *)p1;
}
/* find the end of suffix */
for (p3=(char *)suff; *p3; p3++)
;
/* early out */
while (p1>p2 && p3>suff) {
if (*--p3 != *--p1)
return p2;
}
/* stash and return filename, sans suffix */
bu_strlcpy(buf, p2, p1-p2+1);
return buf;
}
示例15: PL_FORTRAN
/*
* This FORTRAN interface expects REAL args (single precision).
*/
void
PL_FORTRAN(f2symb, F2SYMB)(FILE **fp, char *string, float *x, float *y, float *scale, float *theta)
{
char buf[128] = {0};
bu_strlcpy( buf, string, sizeof(buf) );
tp_2symbol( *fp, buf, *x, *y, *scale, *theta );
}