当前位置: 首页>>代码示例>>C++>>正文


C++ xalloc_die函数代码示例

本文整理汇总了C++中xalloc_die函数的典型用法代码示例。如果您正苦于以下问题:C++ xalloc_die函数的具体用法?C++ xalloc_die怎么用?C++ xalloc_die使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xalloc_die函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: xgetcwd

char *
xgetcwd ()
{
#if HAVE_GETCWD_NULL
  char *cwd = getcwd (NULL, 0);
  if (! cwd && errno == ENOMEM)
    xalloc_die ();
  return cwd;
#else

  /* The initial buffer size for the working directory.  A power of 2
     detects arithmetic overflow earlier, but is not required.  */
# ifndef INITIAL_BUFFER_SIZE
#  define INITIAL_BUFFER_SIZE 128
# endif

  size_t buf_size = INITIAL_BUFFER_SIZE;

  while (1)
    {
      char *buf = xmalloc (buf_size);
      char *cwd = getcwd (buf, buf_size);
      int saved_errno;
      if (cwd)
	return cwd;
      saved_errno = errno;
      free (buf);
      if (saved_errno != ERANGE)
	return NULL;
      buf_size *= 2;
      if (buf_size == 0)
	xalloc_die ();
    }
#endif
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:35,代码来源:xgetcwd.c

示例2: savedir

char *
savedir (const char *dir)
{
  DIR *dirp;
  struct dirent *dp;
  char *name_space;
  size_t allocated = NAME_SIZE_DEFAULT;
  size_t used = 0;
  int save_errno;

  dirp = opendir (dir);
  if (dirp == NULL)
    return NULL;

  name_space = xmalloc (allocated);

  errno = 0;
  while ((dp = readdir (dirp)) != NULL)
    {
      /* Skip "", ".", and "..".  "" is returned by at least one buggy
         implementation: Solaris 2.4 readdir on NFS filesystems.  */
      char const *entry = dp->d_name;
      if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
	{
	  size_t entry_size = strlen (entry) + 1;
	  if (used + entry_size < used)
	    xalloc_die ();
	  if (allocated <= used + entry_size)
	    {
	      do
		{
		  if (2 * allocated < allocated)
		    xalloc_die ();
		  allocated *= 2;
		}
	      while (allocated <= used + entry_size);

	      name_space = xrealloc (name_space, allocated);
	    }
	  memcpy (name_space + used, entry, entry_size);
	  used += entry_size;
	}
    }
  name_space[used] = '\0';
  save_errno = errno;
  if (CLOSEDIR (dirp) != 0)
    save_errno = errno;
  if (save_errno != 0)
    {
      free (name_space);
      errno = save_errno;
      return NULL;
    }
  return name_space;
}
开发者ID:WndSks,项目名称:msys,代码行数:55,代码来源:savedir.c

示例3: time_to_env

static void
time_to_env (char *envar, struct timespec t)
{
  char buf[TIMESPEC_STRSIZE_BOUND];
  if (setenv (envar, code_timespec (t, buf), 1) != 0)
    xalloc_die ();
}
开发者ID:stfp,项目名称:tar-dedup,代码行数:7,代码来源:system.c

示例4: main

int
main (int argc _GL_UNUSED, char **argv)
{
  set_program_name (argv[0]);
  xalloc_die ();
  return 0;
}
开发者ID:AGSaidi,项目名称:hacked-libvirt,代码行数:7,代码来源:test-xalloc-die.c

示例5: xnrealloc_inline

static inline void *
xnrealloc_inline (void *p, size_t n, size_t s)
{
    if (xalloc_oversized (n, s) || (! (p = realloc (p, n * s)) && n != 0))
        xalloc_die ();
    return p;
}
开发者ID:Hotschke,项目名称:Recode,代码行数:7,代码来源:xmalloc.c

示例6: x2nrealloc_inline

static inline void *
x2nrealloc_inline (void *p, size_t *pn, size_t s)
{
    size_t n = *pn;

    if (! p)
    {
        if (! n)
        {
            /* The approximate size to use for initial small allocation
               requests, when the invoking code specifies an old size of
               zero.  64 bytes is the largest "small" request for the
               GNU C library malloc.  */
            enum { DEFAULT_MXFAST = 64 };

            n = DEFAULT_MXFAST / s;
            n += !n;
        }
    }
    else
    {
        if (SIZE_MAX / 2 / s < n)
            xalloc_die ();
        n *= 2;
    }

    *pn = n;
    return xrealloc (p, n * s);
}
开发者ID:Hotschke,项目名称:Recode,代码行数:29,代码来源:xmalloc.c

示例7: strdup

char *xstrdup(const char *s1)
{
	char *s = strdup(s1);
	if (s1 && !s)
		xalloc_die();
	return s;
}
开发者ID:patperry,项目名称:core,代码行数:7,代码来源:xalloc.c

示例8: malloc

void *xmalloc(size_t size)
{
	void *ptr = malloc(size);
	if (size && !ptr)
		xalloc_die();
	return ptr;
}
开发者ID:patperry,项目名称:core,代码行数:7,代码来源:xalloc.c

示例9: bitsetv_alloc

/* Create a vector of N_VECS bitsets, each of N_BITS, and of
   type TYPE.  */
bitset *
bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits,
	       enum bitset_type type)
{
  size_t vector_bytes;
  size_t bytes;
  bitset *bsetv;
  bitset_bindex i;

  /* Determine number of bytes for each set.  */
  bytes = bitset_bytes (type, n_bits);

  /* If size calculation overflows, memory is exhausted.  */
  if (BITSET_SIZE_MAX / (sizeof (bitset) + bytes) <= n_vecs)
    xalloc_die ();

  /* Allocate vector table at head of bitset array.  */
  vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1;
  vector_bytes -= vector_bytes % bytes;
  bsetv = xcalloc (1, vector_bytes + bytes * n_vecs);

  for (i = 0; i < n_vecs; i++)
    {
      bsetv[i] = (bitset) (void *) ((char *) bsetv + vector_bytes + i * bytes);

      bitset_init (bsetv[i], n_bits, type);
    }

  /* Null terminate table.  */
  bsetv[i] = 0;
  return bsetv;
}
开发者ID:119,项目名称:aircam-openwrt,代码行数:34,代码来源:bitsetv.c

示例10: xfts_open

FTS *
xfts_open (char * const *argv, int options,
	   int (*compar) (const FTSENT **, const FTSENT **))
{
  FTS *fts = fts_open (argv, options | FTS_CWDFD, compar);
  if (fts == NULL)
    {
      /* This can fail in three ways: out of memory, invalid bit_flags,
	 and one or more of the FILES is an empty string.  We could try
	 to decipher that errno==EINVAL means invalid bit_flags and
	 errno==ENOENT means there's an empty string, but that seems wrong.
	 Ideally, fts_open would return a proper error indicator.  For now,
	 we'll presume that the bit_flags are valid and just check for
	 empty strings.  */
      bool invalid_arg = false;
      for (; *argv; ++argv)
	{
	  if (**argv == '\0')
	    invalid_arg = true;
	}
      if (invalid_arg)
	error (EXIT_FAILURE, 0, _("invalid argument: %s"), quote (""));
      else
	xalloc_die ();
    }

  return fts;
}
开发者ID:azureplus,项目名称:sha3sums,代码行数:28,代码来源:xfts.c

示例11: record_file

/* Record file, FILE, and dev/ino from *STATS, in the hash table, HT.
   If HT is NULL, return immediately.
   If memory allocation fails, exit immediately.  */
void
record_file (Hash_table *ht, char const *file, struct stat const *stats)
{
  struct F_triple *ent;

  if (ht == NULL)
    return;

  ent = xmalloc (sizeof *ent);
  ent->name = xstrdup (file);
  ent->st_ino = stats->st_ino;
  ent->st_dev = stats->st_dev;

  {
    struct F_triple *ent_from_table = hash_insert (ht, ent);
    if (ent_from_table == NULL)
      {
        /* Insertion failed due to lack of memory.  */
        xalloc_die ();
      }

    if (ent_from_table != ent)
      {
        /* There was alread a matching entry in the table, so ENT was
           not inserted.  Free it.  */
        triple_free (ent);
      }
  }
}
开发者ID:Shivox,项目名称:man-db,代码行数:32,代码来源:file-set.c

示例12: hash_string_insert_prefix

/* Return zero if TABLE contains a LEN-character long prefix of STRING,
   otherwise, insert a newly allocated copy of this prefix to TABLE and
   return 1.  If RETURN_PREFIX is not NULL, point it to the allocated
   copy. */
static bool
hash_string_insert_prefix (Hash_table **table, char const *string, size_t len,
			   const char **return_prefix)
{
  Hash_table *t = *table;
  char *s;
  char *e;

  if (len)
    {
      s = xmalloc (len + 1);
      memcpy (s, string, len);
      s[len] = 0;
    }
  else
    s = xstrdup (string);
  
  if (! ((t
	  || (*table = t = hash_initialize (0, 0, hash_string_hasher,
					    hash_string_compare, 0)))
	 && (e = hash_insert (t, s))))
    xalloc_die ();

  if (e == s)
    {
      if (return_prefix)
	*return_prefix = s;
      return 1;
    }
  else
    {
      free (s);
      return 0;
    }
}
开发者ID:dalinaum,项目名称:gnu-cpio-for-mac,代码行数:39,代码来源:names.c

示例13: xdico_transcript_stream_create

dico_stream_t
xdico_transcript_stream_create(dico_stream_t transport, dico_stream_t logstr,
			       const char *prefix[])
{
    struct transcript_stream *p = xmalloc(sizeof(*p));
    dico_stream_t stream;
    int rc = dico_stream_create(&stream, DICO_STREAM_READ|DICO_STREAM_WRITE,
				p);
    if (rc)
	xalloc_die();
    p->flags = TRANS_READ | TRANS_WRITE;
    if (prefix) {
	p->prefix[0] = xstrdup(prefix[0] ? prefix[0] : default_prefix[0]);
	p->prefix[1] = xstrdup(prefix[1] ? prefix[1] : default_prefix[1]);
    } else {
	p->prefix[0] = xstrdup(default_prefix[0]);
	p->prefix[1] = xstrdup(default_prefix[1]);
    }
    p->transport = transport;
    p->logstr = logstr;
    
    dico_stream_set_read(stream, transcript_read);
    dico_stream_set_write(stream, transcript_write);
    dico_stream_set_flush(stream, transcript_flush);
    dico_stream_set_close(stream, transcript_close);
    dico_stream_set_destroy(stream, transcript_destroy);
    dico_stream_set_ioctl(stream, transcript_ioctl);
    dico_stream_set_error_string(stream, transcript_strerror);
    dico_stream_set_buffer(stream, dico_buffer_line, 1024);

    return stream;
}
开发者ID:baohaojun,项目名称:dico,代码行数:32,代码来源:xscript.c

示例14: malloc

void *xmalloc (size_t size)
{
    void *mem = malloc(size);
    if (mem == NULL)
        xalloc_die();
    return mem;
}
开发者ID:osklil,项目名称:rdpvnclaunch,代码行数:7,代码来源:xmalloc.c

示例15: realloc

void *xrealloc (void *ptr, size_t size)
{
    void *mem = realloc(ptr, size);
    if (mem == NULL)
        xalloc_die();
    return mem;
}
开发者ID:osklil,项目名称:rdpvnclaunch,代码行数:7,代码来源:xmalloc.c


注:本文中的xalloc_die函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。