Hi,
   I am writing a simple program to print the size of a file on disk. But 
surprisingly my program keeps printing 0 on Darwin (but works on a PC running 
Linux). Here's two set of programs I wrote, one using stat posix api and other 
using Carbon CoreServices. Neither of them works. If someone can tell me whats 
wrong or suggest a way of getting file size correctly, please let me know.

Thanks
Vijay

Posix:
--------
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

main(int argc, char **argv)
{
  struct stat sb;
  int retval;

  if(argc<2){
        fprintf(stderr,"Usage: %s <filename>\n", argv[0]);
        exit(1);
  }

  retval = stat(argv[1], &sb);

  if(retval==0) printf("Size of %s, uid %d, is %d\n", argv[1], sb.st_uid, 
sb.st_size);
  else perror("stat");
}

CoreServices:
-------------------
OSStatus PrintFileSize(char *path)
{
   OSStatus err=noErr;
   FSRef ref;
   FSCatalogInfo cataloginfo;
   
   err = FSPathMakeRef("/Users/vijayv/dd.txt", &ref, NULL);
   
   require_noerr(err, CantMakeRef);
   
   err = FSGetCatalogInfo (&ref, kFSCatInfoDataSizes, &cataloginfo, NULL, NULL, 
NULL);
   
   require_noerr (err, CantGetCatalogInfo);

   printf("File size is %d\n", cataloginfo.dataLogicalSize);
   
    return err;
    
CantMakeRef:
    printf("Cant make ref\n");
    
CantGetCatalogInfo:
    printf("Cant get catalog info\n");
    
    return err;
}



 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to