本文整理汇总了C++中enomem函数的典型用法代码示例。如果您正苦于以下问题:C++ enomem函数的具体用法?C++ enomem怎么用?C++ enomem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enomem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_sqconfig
void write_sqconfig(const char *dir, const char *configfile, const char *val)
{
char *p=malloc(strlen(dir) + strlen(configfile) + 2);
FILE *f;
if (!p) enomem();
strcat(strcat(strcpy(p, dir), "/"), configfile);
if (!val)
unlink(p);
else
{
f=fopen(p, "w");
if (!f) enomem();
fprintf(f, "%s\n", val);
fflush(f);
if (ferror(f)) enomem();
fclose(f);
/* Note - umask should already turn off the 077 bits, but
** just in case someone screwed up previously, I'll fix it
** myself */
chmod(p, 0600);
}
free(p);
}
示例2: enomem
static char *getgpgconfig(const char *name)
{
const char *p;
char *q, *r;
int name_l=strlen(name);
p=read_sqconfig(".", GPGCONFIGFILE, 0);
if (p)
{
q=strdup(p);
if (!q)
enomem();
for (r=q; (r=strtok(r, " ")) != NULL; r=NULL)
if (strncmp(r, name, name_l) == 0 &&
r[name_l] == '=')
{
r=strdup(r+name_l+1);
free(q);
if (!r)
enomem();
return (r);
}
free(q);
}
return (NULL);
}
示例3: login_changepwd
int login_changepwd(const char *u, const char *oldpwd, const char *newpwd,
int *rc)
{
char *uid=strdup(u);
char *driver;
int i;
if (!uid)
enomem();
verifyuid(uid);
if ((driver=strrchr(uid, '.')) == 0)
{
free(uid);
enomem();
}
*driver++=0;
for (i=0; authstaticmodulelist[i]; i++)
{
if (strcmp(authstaticmodulelist[i]->auth_name, driver) == 0)
{
*rc=badstr(uid) || badstr(oldpwd) || badstr(newpwd)
? 1:(*authstaticmodulelist[i]->auth_changepwd)
("webmail", uid, oldpwd, newpwd);
free(uid);
return (0);
}
}
return (-1);
}
示例4: once_init
rt_public void once_init (void)
{
EIF_GET_CONTEXT
#if !defined(WORKBENCH) && !defined (EIF_THREADS)
int32 old_egc_prof_enabled = egc_prof_enabled; /* Save profiler status */
egc_prof_enabled = 0; /* Disable profiler as it is not initialized yet. */
#endif
ALLOC_ONCE_INDEXES; /* Allocate array of once indexes. */
egc_system_mod_init (); /* Assign once indexes. */
#if !defined(WORKBENCH) && !defined (EIF_THREADS)
egc_prof_enabled = old_egc_prof_enabled; /* Restore profiler status. */
#endif
if (!debug_mode) {
/* Once indexes could be used by debugger,
* but we are not under debugger at the moment. */
FREE_ONCE_INDEXES; /* Free once indexes. */
}
/* Allocate room for once manifest strings array. */
ALLOC_OMS (EIF_oms);
if (EIF_once_count == 0) {
EIF_once_values = (EIF_once_value_t *) 0;
} else {
/* Allocate room for once values. */
EIF_once_values = (EIF_once_value_t *) eif_realloc (EIF_once_values, EIF_once_count * sizeof *EIF_once_values);
/* needs malloc; crashes otherwise on some pure C-ansi compiler (SGI)*/
if (EIF_once_values == (EIF_once_value_t *) 0) /* Out of memory */
enomem();
memset (EIF_once_values, 0, EIF_once_count * sizeof *EIF_once_values);
}
#ifdef EIF_THREADS
if (EIF_process_once_count == 0) {
EIF_process_once_values = (EIF_process_once_value_t *) 0;
} else {
/* Allocate room for process-relative once values. */
EIF_process_once_values = (EIF_process_once_value_t *) eif_realloc (EIF_process_once_values, EIF_process_once_count * sizeof *EIF_process_once_values);
/* needs malloc; crashes otherwise on some pure C-ansi compiler (SGI)*/
if (EIF_process_once_values == (EIF_process_once_value_t *) 0) /* Out of memory */
enomem();
memset (EIF_process_once_values, 0, EIF_process_once_count * sizeof *EIF_process_once_values);
{
int i = EIF_process_once_count;
while (i > 0) {
i--;
EIF_process_once_values [i].mutex = eif_thr_mutex_create ();
}
}
}
#endif
}
示例5: setgpgconfig
static void setgpgconfig(const char *name, const char *value)
{
const char *p;
char *q, *r, *s;
int name_l=strlen(name);
/* Get the existing settings */
p=read_sqconfig(".", GPGCONFIGFILE, 0);
if (!p)
p="";
q=strdup(p);
if (!q)
enomem();
s=malloc(strlen(q)+strlen(name)+strlen(value)+4);
if (!s)
enomem();
*s=0;
/*
** Copy existing settings into a new buffer, deleting any old
** setting.
*/
for (r=q; (r=strtok(r, " ")) != NULL; r=NULL)
{
if (strncmp(r, name, name_l) == 0 &&
r[name_l] == '=')
{
continue;
}
if (*s)
strcat(s, " ");
strcat(s, r);
}
/* Append the new setting */
if (*s)
strcat(s, " ");
strcat(strcat(strcat(s, name), "="), value);
free(q);
write_sqconfig(".", GPGCONFIGFILE, s);
free(s);
}
示例6: fclose
const char *myhostname()
{
char buf[512];
static char *my_hostname=0;
FILE *f;
if (my_hostname == 0)
{
buf[0]=0;
if ((f=fopen(HOSTNAMEFILE, "r")) != 0)
{
char *p;
if (fgets(buf, sizeof(buf), f) == NULL)
buf[0]=0;
fclose(f);
if ((p=strchr(buf, '\n')) != 0)
*p=0;
}
if (buf[0] == 0 && gethostname(buf, sizeof(buf)-1))
strcpy(buf, "localhost");
if ((my_hostname=malloc(strlen(buf)+1)) == 0)
enomem();
strcpy(my_hostname, buf);
}
return (my_hostname);
}
示例7: setup_log_file
/* Setup the logging output mechanism. */
int
setup_log_file(CONFIG *cfg)
{
char *fname;
if (cfg->verbose < 1)
return (0);
if ((fname = calloc(strlen(cfg->home) +
strlen(cfg->table_name) + strlen(".stat") + 2, 1)) == NULL)
return (enomem(cfg));
sprintf(fname, "%s/%s.stat", cfg->home, cfg->table_name);
cfg->logf = fopen(fname, "w");
free(fname);
if (cfg->logf == NULL) {
fprintf(stderr,
"Failed to open log file: %s\n", strerror(errno));
return (EINVAL);
}
/* Use line buffering for the log file. */
(void)setvbuf(cfg->logf, NULL, _IOLBF, 0);
return (0);
}
示例8: sizeof
static char *append_str(const char *prefs, const char *label,
const char *value)
{
int l=strlen(prefs) + sizeof(" =") +
strlen(label)+ (value ? strlen(value):0);
int i;
char *p;
const char *q;
for (i=0; value && value[i]; i++)
if (value[i] <= ' ' || value[i] >= 127
|| value[i] == '+')
l += 2;
p=malloc(l);
if (!p) enomem();
strcpy(p, prefs);
if (!value || !*value) return (p);
strcat(strcat(strcat(p, " "), label), "=");
i=strlen(p);
for (q=value; *q; q++)
{
if (*q <= ' ' || *q >= 127 || *q == '+')
{
sprintf(p+i, "+%02X", (int)(unsigned char)*q);
i += 3;
continue;
}
p[i++]= *q;
}
p[i]=0;
return (p);
}
示例9: emalloc
/*
* emalloc --
* malloc, but die on error.
*/
void * emalloc(size_t len) {
void * ptr = malloc(len);
if( ptr == NULL )
enomem();
return ptr;
}
示例10: ecalloc
/*
* ecalloc --
* calloc, but die on error.
*/
void * ecalloc(size_t nmemb, size_t size) {
void * ptr = calloc(nmemb, size);
if( ptr == NULL )
enomem();
return ptr;
}
示例11: save_arg
static void
save_arg(args_t *args, char *arg1, ...)
{
char *carg;
va_list argp;
va_start(argp, arg1);
carg = arg1;
while (carg) {
if (args->no <= args->ix) {
args->vec = (char **) (args->no
? realloc((void *) args->vec,
(sizeof(char *)
*(args->no + ARGS_INCR + 1)))
: malloc((sizeof(char *)
*(args->no + ARGS_INCR + 1))));
if (!args->vec)
enomem();
args->no += ARGS_INCR;
}
args->vec[args->ix++] = carg;
args->chars += strlen(carg);
carg = va_arg(argp, char *);
}
args->vec[args->ix++] = " ";
args->chars++;
va_end(argp);
}
示例12: spellignore
static int spellignore(const char *word)
{
char buf[100];
const char *c;
char *p, *q;
FILE *fp=opendict("r");
if (!fp) return (0);
while (fgets(buf, sizeof(buf), fp) != NULL)
{
if ((p=strchr(buf, '\n')) != 0) *p=0;
if (strcmp(word, buf) == 0)
{
fclose(fp);
return (1);
}
}
fclose(fp);
c=cgi("globignore");
p=malloc(strlen(c)+1);
if (!p) enomem();
strcpy(p, c);
for (q=p; (q=strtok(q, ":")) != 0; q=0)
if (strcmp(q, word) == 0)
{
free(p);
return (1);
}
return (0);
}
示例13: bmake_realloc
/*
* bmake_realloc --
* realloc, but die on error.
*/
void *
bmake_realloc(void *ptr, size_t size)
{
if ((ptr = realloc(ptr, size)) == NULL)
enomem();
return(ptr);
}
示例14: new_V3
void new_V3(
float x,
float y,
float z)
{
if (!current_prim) {
printf("!!! ignoring V3 outside of prim\n");
return;
}
struct prim_t * p = current_prim;
struct V3_t * v = p->V3;
if (!v) {
v = malloc(sizeof(*v));
p->V3 = v;
} else {
while (v->next)
v = v->next;
v->next = malloc(sizeof(*v));
v = v->next;
}
if (!v) enomem();
v->next = NULL;
v->norm = norm_last;
v->v.x = x;
v->v.y = y;
v->v.z = z;
p->nV3++;
}
示例15: estrdup
/*
* estrdup --
* strdup, but die on error.
*/
char * estrdup(const char * str) {
char * ptr = strdup(str);
if( ptr == NULL )
enomem();
return ptr;
}