天天看點

Linux伺服器程式設計之:link()函數,ln指令,symlink,readlink,案例說明

1 link()依賴頭檔案

#include<unistd.h>

2函數定義

int link(const char *oldpath,const char *newpath);

函數說明:

 link()  creates  a  new link (also known as a hard link) to an existing

       file.

       翻譯:link()函數為一個已經存在的檔案建立一個新的連結(也就是通常所說的“硬連結”)

if newpath exists it will not be overwritten.

       翻譯:如果新檔案已經存在,它将不會被重寫

this new name may be used exactly as the old  one  for  any  operation;

       both names refer to the same file (and so have the same permissions and

       ownership) and it is impossible to tell which name was the "original".

       翻譯:新的名字可以替代舊的名字做任何操作,這些名字都指向同一個檔案(并且也有相同的權限和擁有者),并且很難辨識哪個名稱是原始的名稱

3.傳回值

      一旦成功,傳回0,一旦錯誤,傳回-1。并且erron被設定了結果

4.案例說明:

Linux伺服器程式設計之:link()函數,ln指令,symlink,readlink,案例說明
Linux伺服器程式設計之:link()函數,ln指令,symlink,readlink,案例說明

5.ln指令

說明:

        a:連結有兩種,一種被稱為硬連結(hard link),另外一種被稱為符号連結(symbol link),也叫軟連結。建立硬連結時,連結檔案和被連結檔案必須位于同一個檔案系統中,

并且不能建立指向目錄的硬連結。而對于符号連結,則不存在這個問題。預設情況下,ln産生硬連結

Linux伺服器程式設計之:link()函數,ln指令,symlink,readlink,案例說明

6.symlink依賴的頭檔案

函數定義:

int symlink(const char *oldpath, const char *newpath);

描述:

symlink()  creates  a  symbolic  link  named newpath which contains the

       string oldpath.

7.readlink

讀符号連結所指向的檔案名字,不讀檔案内容

ssize_t readlink(const char *path, char *buf, size_t bufsiz)



繼續閱讀