truncate and ftruncate?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

truncate and ftruncate?

Post by theHobbit »

Hi, does any one knows if the truncate and ftruncate functions are implemented in the pspsdk? Cuz i get an 'undefined reference to ftruncate' error whenever I try to compile a simple test with these function!!

Hope anyone can help. Thanks in advance!!
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Truncate is, ftruncate isn't.
There was some code here but I don't think it was ever merged.
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

Thanks I have already tryied that:

Code: Select all

int ftruncate(int fd, off_t length) 
{ 
   int ret; 
   SceOff oldpos; 
   if (!__PSP_IS_FD_VALID(fd)) { 
      errno = EBADF; 
      return -1; 
   } 

   switch(__psp_descriptormap[fd]->type) 
   { 
      case __PSP_DESCRIPTOR_TYPE_FILE: 
         if (__psp_descriptormap[fd]->filename != NULL) { 
            if (!(__psp_descriptormap[fd]->flags & (O_WRONLY | O_RDWR))) 
               break; 
            return truncate(__psp_descriptormap[fd]->filename, length); 
            /* ANSI sez ftruncate doesn't move the file pointer */ 
         } 
         break; 
      case __PSP_DESCRIPTOR_TYPE_TTY: 
      case __PSP_DESCRIPTOR_TYPE_PIPE: 
      case __PSP_DESCRIPTOR_TYPE_SOCKET: 
      default: 
         break; 
   } 

   errno = EINVAL; 
   return -1; 
} 
but i'm a little lost. Is it some kind of patch to the pspsdk cuz I just pasted it in my code but cant compile it, i get several undefined references to: __PSP_DESCRIPTOR_TYPE, __psp_descriptormap, etc...

Well anyone have used it successfully?
Post Reply