YedFileMan - Examples

Various operations performed with files into file system through YedFileMan object:

#include <stdio.h>
#include <errno.h>
#include <yedstd.h>
#include <yedfileman.h>

main() {
int s,i;
YedFileMan *p=New(YedFileMan);
SCHAR scbPath[120]="\0";
SCHAR scbAppo[120]="\0";
SCHAR *pscCont;

// GET SIZE OF FILE /etc/hosts

s=p->Get_Size(p,"/etc/hosts");
if(s<YFSUCCESS)
  printf("Error [%d] in Get_Size\n",errno);
else
  printf("Size of /etc/hosts: [%ld]\n",s);

// LOADING OF FILE /etc/group INTO THE HEAP MEMORY

pscCont=p->Load(p,"/etc/group",&i);
if(pscCont!=NULL) {
  printf("Content of file /etc/group, size [%d]:\n[[[%s]]]\n",
         i,pscCont);
  free(pscCont);
}
else
  printf("Errore in load file:%d\n",errno);

// CREATION OF SYMBOLIC LINK k1 TO A FILE kk IN APPLICATION CURRENT DIRECTORY

s=p->Copy(p,"kk","k1",YF_SYMLINK);
if(s<YFSUCCESS)
  printf("Error in copying file [%d] - errno [%d]\n",s,errno);
else
  printf("Copying OK\n");

strcpy(scbPath,"kk");

// CHECKING TYPE OF FILE FILE kk THROUGH IS_... METHODS

if((p->Is_File(p,scbPath))) printf("%s is a file!\n",scbPath);
if((p->Is_Link(p,scbPath))) printf("%s is a link!\n",scbPath);
if((p->Is_Directory(p,scbPath))) printf("%s is a directory!\n",scbPath);
if((p->Is_Socket(p,scbPath))) printf("%s is a socket!\n",scbPath);

// GET GID E UID AND DATE OF FILE kk

printf("File [%s] GID [%d] UID [%d]\n",
       scbPath,p->Get_GID(p,scbPath),p->Get_UID(p,scbPath));
printf("File [%s] last access [%s]\n",
       scbPath,p->Get_Time(p,scbPath,ACCESS,scbAppo,120,"%F %R"));
printf("File [%s] last modify [%s]\n",
       scbPath,p->Get_Time(p,scbPath,MODIFY,scbAppo,120,"%F %R"));
printf("File [%s] last status change [%s]\n",
       scbPath,p->Get_Time(p,scbPath,CHANGE,scbAppo,120,"%F %R"));

// MOVE FILE k1 IN THE FILE k1_MOVE

s=p->Move(p,"k1","k1_move",0);
if(s<YFSUCCESS)
  printf("Error [%d] in moving file k1 - errno [%d]\n",s,errno);
else
  printf("Moving OK\n");

// EXAMPLE OF BASENAME AND DIRNAME METHODS

printf("[%s]\n",p->Basename(p,"/etc/hosts"));
s=p->Dirname(p,"/etc/dir/dir1/dir2/dir3/ciao.web",scbPath,120);
printf("%d[%s]\n",s,scbPath);

// RELEASE OBJECT INSTANCE

Delete(YedFileMan,p);
}


http://yed.sourceforge.net