為路徑名動態地分配空間

2021-08-30 03:12:28 字數 832 閱讀 3639

#include "apue.h"

#include #include #ifdef path_max

static int pathmax=path_max;

#else

static int pathmax=0;

#endif

#define susv3 200112l

static long posix_version=0;

#define path_max_guess 1024

char * path_alloc(int *sizep)

else

} 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;

}

如果在中定義了常量path_max,那麼就沒有任何;如果沒有定義,則需呼叫pathconf。因為pathconf的返回值是基於工作目錄的相對路徑名的最大長度,而工作目錄是其第乙個引數,所以,指定根目錄為第乙個引數,並將得到的返回值加1作為其結果值。如果pathconf指明path_max是不確定的,那麼我們只能猜測某個值。

對於path_max是否在路徑名末尾包括乙個null字元這一點,sus v3之前的標準表述得不清楚。出於安全方面的考慮,如果作業系統實現遵循先前的標準版本,則需要在為路徑名分配的儲存數量上加1。

Python分解路徑名

python分解路徑名的實際操作步驟的介紹,其中我們會設定很多的假設,以及一些相關 的介紹,以方便你在學習的過程中更好的掌握python分解路徑名的實際操作步驟。python分解路徑名假設我們使用變數fname來存放乙個包含完整路徑的檔名,例如 usr home hpl scripting pyth...

獲取模組檔案路徑名

獲取模組檔案路徑名 static bool getmodulepathname cstdstring strmodulepathname zeromemory szdrive,sizeof szdrive zeromemory szdir,sizeof szdir zeromemory szfile...

Ubuntu 終端路徑名改短

1.改變home目錄下的.bashrc檔案,修改這個只會在home目錄下生效 1.vi bashrc 2.找到下面的的 if color prompt yes then ps1 033 01 32m u h 033 00m 033 01 34m w 033 00m else ps1 u h w 將其...