deftype.h source code

//	deftype.h
//	BarSSoft, 1999

#ifndef __DEFTYPE_H__
#define __DEFTYPE_H__

#include <time.h>

void* defineType(void* fileInf);

#endif

deftype.c source code

#include <stdio.h>
#include <strings.h>
#include "deftype.h"
#include "filelist.h"
#include "stat.h"
#include "readir.h"


void* defineType(void* fileInf)
{
   char *buf, *argStr, *posb, *pose;
   FILE *fptr;

   buf = (char*)malloc(256);
   argStr = (char*)malloc(strlen(((FileInf*) fileInf)->name) + 6);
   strcpy(argStr, "file ");
   strcat(argStr, ((FileInf*) fileInf)->name);
   
   fptr = popen(argStr, "r");

   if (fptr)
   {
      fgets(buf, 255, fptr);
      posb = strchr(buf, ':');
      if (posb)
      {      
         posb += 2;    
         pose = strchr(posb, ',');
         if (pose)
         {
            strncpy(buf, posb,  pose - posb);  
            *(buf + (pose - posb)) = '\0';
         }
         else   
            strcpy(buf, posb);
            
         if (pose = strchr(buf, '\n'))
            *pose = '\0';   
      }      

      ((FileInf*)fileInf)->type = (char*)malloc(strlen(buf) + 1);
      strcpy(((FileInf*)fileInf)->type, buf);
  
      pthread_mutex_lock(&lockFileList);
      fileList_Add(fileInf);
   
      pthread_mutex_unlock(&lockFileList);

  
      pclose(fptr);
   }
   
   free(buf);
   free(argStr);  
   
   if (showStat)
      pthread_cond_signal(&condStatusChanged);
}