Linux's Path_alloc function

Source: Internet
Author: User
Tags int size
 #include "apue.h" #include <errno.h> #include <limits.h> #ifdef path_max static int pathmax = PA 
Th_max; 
#else static int pathmax = 0; 
#endif #define SUSV3 200112L static long posix_version = 0; /* If Path_max is indeterminate, no guarantee it is adequate */#define PATH_MAX_GUESS 1024 char * path_alloc (int *s 
IZEP)/* Also return allocated size, if nonnull/{char *ptr; 
int size; 
if (posix_version = = 0) posix_version = sysconf (_sc_version);       if (Pathmax = = 0) {/*//* through/errno = 0; 
            /* from:http://www.bianceng.cn */if (Pathmax = pathconf ("/", _pc_path_max)) < 0) {if (errno = 0) Pathmax = path_max_guess; 
       /* it ' s indeterminate/Else Err_sys ("pathconf error for _pc_path_max");    else {pathmax++; 
/* Add one since it ' s relative to root *} if (Posix_version < SUSV3) size = Pathmax + 1; else size = Pathmax; 
if (ptr = malloc (size) = = NULL) Err_sys ("malloc error for pathname"); 
if (Sizep!= NULL) *sizep = size; 
return (PTR); } or Char*path_alloc (int* size) {char *p = null; if (!size) return null; p = malloc (256); if (p) *size = 256; else *si
ze = 0;
return p; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.