DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ D T

⟦c43cd41ee⟧ TextFile

    Length: 7750 (0x1e46)
    Types: TextFile
    Names: »DIRECTORY_C«

Derivation

└─⟦149519bd4⟧ Bits:30000546 8mm tape, Rational 1000, !projects 93-07-13
    └─ ⟦124ff5788⟧ »DATA« 
        └─⟦this⟧ 
└─⟦a7d1ea751⟧ Bits:30000550 8mm tape, Rational 1000, !users!projects 94_04_11
    └─ ⟦129cab021⟧ »DATA« 
        └─⟦this⟧ 
└─⟦f64eaa120⟧ Bits:30000752 8mm tape, Rational 1000, !projects 93 02 16
    └─ ⟦6f12a12be⟧ »DATA« 
        └─⟦this⟧ 
└─⟦2f6cfab89⟧ Bits:30000547 8mm tape, Rational 1000, !projects 94-01-04
    └─ ⟦d65440be7⟧ »DATA« 
        └─⟦this⟧ 

TextFile

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <usersec.h>
#include <time.h>
#include <sys/mode.h>
#include <string.h>
#include <fcntl.h>
#include <regex.h>
#include <fcntl.h>
#include <errno.h>

struct dirent *(*NameList[]);
int alphasort();
DIR *DirectoryPointer = NULL;
static struct stat DirectoryStat;
static regex_t Re;

static char *adastr(char *str)
{
  char lg[10];
  char *result;
  sprintf(lg, "%d", strlen(str));
  result = malloc(strlen(lg)+strlen(str)+2);
  sprintf(result, "%s,%s", lg, str);
  return result;
}

int select(struct dirent *Name)
{
  return (regexec(&Re, Name->d_name, (size_t) 0, NULL, 0) == 0);
}

char *GetErrorMessage()
{
  return adastr(strerror(errno));
}

char *GetHomeDirectory()
{
  char *Home = getenv("HOME");
  return adastr(Home);
}

char *GetAbsolutePath(char *PathName)
{
  char currentpath[256];
  char path[256];
  getwd(currentpath);
  if (chdir(PathName)==0)
  {
    getwd(path);
    chdir(currentpath);
    return adastr(path);
  }
  else
    return adastr("");
}

int ChangeDirectory(char *PathName)
{
  return chdir(PathName);
}

int ScanDirectory(char *PathName, char *Pattern)
{
  int itermax;
  if ((regcomp(&Re, Pattern, REG_EXTENDED|REG_NOSUB)) != 0)
    return -1;
  free(NameList);
  itermax = scandir(PathName, NameList, select, alphasort);
  regfree(&Re);
  return itermax;
} 

int CreateFile(char *PathName, int Owner, int Group, int Other)
{
  int n;
  mode_t mode = ( (Owner*8*8) + (Group*8) + Other);
  mode_t mask = umask(0);
  n = creat(PathName, mode);
  umask(mask);
  if (n>0) 
    close(n);
  return (n>0);
}

int CreateDirectory(char *PathName, int Owner, int Group, int Other)
{
  mode_t mode = ( (Owner*8*8) + (Group*8) + Other);
  mode_t mask = umask(0);
  int n = mkdir(PathName, mode);
  umask(mask);
  return n;
}

int move(char *FromPath, char *ToPath)
{
  return rename(FromPath, ToPath);
}

int DirectoryEntryExistent(char *PathName)
{
  return stat(PathName, &DirectoryStat);
}

char *DirectoryEntryValue(int i)
{
  return adastr((*NameList)[i]->d_name);
}

int DirectoryEntrySize(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return DirectoryStat.st_size;
}

int DirectoryEntryNumberOfLinks(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return DirectoryStat.st_nlink;
}

char *DirectoryEntryUserName(char *PathName)
{
  char str[24];
  stat(PathName, &DirectoryStat);
  sprintf(str, "%s", IDtouser(DirectoryStat.st_uid));
  return adastr(str);
}

char *DirectoryEntryGroupName(char *PathName)
{
  char str[24];
  stat(PathName, &DirectoryStat);
  sprintf(str, "%s", IDtogroup(DirectoryStat.st_gid));
  return adastr(str);
}

char *DirectoryEntryDateOfLastAccess(char *PathName)
{
  struct tm *ti;
  char string[10];
  char format[] = "%d%m%Y";
  stat(PathName, &DirectoryStat);
  ti = localtime(&DirectoryStat.st_atime);
  strftime(string, 10, format, ti); 
  return adastr(string);  
}

int DirectoryEntryTimeOfLastAccess(char *PathName)
{
  struct tm *ti;
  int result;
  stat(PathName, &DirectoryStat);
  ti = localtime(&DirectoryStat.st_atime);
  result = ((ti->tm_hour * 3600) + (ti-> tm_min * 60) + ti->tm_sec);
  return result;  
}

char *DirectoryEntryDateOfLastUpdate(char *PathName)
{
  struct tm *ti;
  char string[10];
  char format[] = "%d%m%Y";
  stat(PathName, &DirectoryStat);
  ti = localtime(&DirectoryStat.st_mtime);
  strftime(string, 10, format, ti);
  return adastr(string);  
}

int DirectoryEntryTimeOfLastUpdate(char *PathName)
{
  struct tm *ti;
  int result;
  stat(PathName, &DirectoryStat);
  ti = localtime(&DirectoryStat.st_mtime);
  result =  ((ti->tm_hour * 3600) + (ti-> tm_min * 60) + ti->tm_sec);
  return result;  
}

char *DirectoryEntryDateOfLastStatusChange(char *PathName)
{
  struct tm *ti;
  char string[10];
  char format[] = "%d%m%Y";
  stat(PathName, &DirectoryStat);
  ti = localtime(&DirectoryStat.st_ctime);
  strftime(string, 10, format, ti); 
  return adastr(string);  
}

int IsDirectory(char *PathName)
{
  stat(PathName, &DirectoryStat);  
  return S_ISDIR(DirectoryStat.st_mode);
}

int IsRegularFile(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return S_ISREG(DirectoryStat.st_mode);
}

int IsBlocSpecial(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return S_ISBLK(DirectoryStat.st_mode);
}

int IsCharacterSpecial(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return S_ISCHR(DirectoryStat.st_mode);
}

int IsFifo(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return S_ISFIFO(DirectoryStat.st_mode);
}

int IsSocket(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return S_ISSOCK(DirectoryStat.st_mode);
}

int IsSymbolicLink(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return S_ISLNK(DirectoryStat.st_mode);
}

int IsMultiplexCharacterSpecial(char *PathName)
{
  stat(PathName, &DirectoryStat);
  return S_ISMPX(DirectoryStat.st_mode);
}

int EntryOwnerPermissions(char *PathName)
{
  int n;
  stat(PathName, &DirectoryStat);
  n = ((DirectoryStat.st_mode & S_IRUSR) + (DirectoryStat.st_mode & S_IWUSR) + (DirectoryStat.st_mode & S_IXUSR)) / (8*8);
  return n;
}

int EntryGroupPermissions(char *PathName)
{
  int n;
  stat(PathName, &DirectoryStat);
  n = ((DirectoryStat.st_mode & S_IRGRP) + (DirectoryStat.st_mode & S_IWGRP) + (DirectoryStat.st_mode & S_IXGRP)) / 8;
  return n;
}

int EntryOtherPermissions(char *PathName)
{
  int n;
  stat(PathName, &DirectoryStat);
  n = (DirectoryStat.st_mode & S_IROTH) + (DirectoryStat.st_mode & S_IWOTH) + (DirectoryStat.st_mode & S_IXOTH);
  return n;
}

void ChangeOwnerPermissions(char *PathName, int Mode)
{
  mode_t mode;
  stat(PathName, &DirectoryStat);
  mode = DirectoryStat.st_mode & ~S_IRWXU;
  mode = mode | (Mode * 8*8);
  chmod(PathName, mode);
}   

void ChangeGroupPermissions(char *PathName, int Mode)
{
  mode_t mode;
  stat(PathName, &DirectoryStat);
  mode = DirectoryStat.st_mode & ~S_IRWXG;
  mode = mode | (Mode * 8);
  chmod(PathName, mode);
}

void ChangeOtherPermissions(char *PathName, int Mode)
{
  mode_t mode;
  stat(PathName, &DirectoryStat);
  mode = DirectoryStat.st_mode & ~S_IRWXO;
  mode = mode | Mode;
  chmod(PathName, mode);
}

int CopyFile(char *PathName1, char *PathName2)
{
  FILE *f1, *f2;
  int char_number;
  char buffer[255];
  if ((f1=fopen(PathName1,"r"))==NULL)
    return -1;
  else
  {
    CreateFile(PathName2, EntryOwnerPermissions(PathName1), EntryGroupPermissions(PathName2), EntryOtherPermissions(PathName1));
    if ((f2=fopen(PathName2, "w"))==NULL)
      return -2;
    else 
      while ((char_number=fread(buffer, sizeof(char), 255, f1))>0)
        fwrite(buffer, sizeof(char), char_number, f2);
  }
  fclose(f1);
  fclose(f2);
  return 0; 
}

int CopyDirectory(char *PathName1, char *PathName2)
{
  DIR *DirectoryPointer;
  struct dirent *dp;
  char *Path1, *Path2;
  int n = 0;
  CreateDirectory(PathName2, EntryOwnerPermissions(PathName1), EntryGroupPermissions(PathName1),
EntryOtherPermissions(PathName1)); 
  DirectoryPointer = opendir(PathName1);
  readdir(DirectoryPointer);
  readdir(DirectoryPointer);
  for (dp = readdir(DirectoryPointer); dp!=NULL && n==0; dp = readdir(DirectoryPointer))
  {
    Path1 = malloc(strlen(PathName1)+dp->d_namlen+2);
    Path2 = malloc(strlen(PathName2)+dp->d_namlen+2);
    sprintf(Path1, "%s/%s", PathName1, dp->d_name);
    sprintf(Path2, "%s/%s", PathName2, dp->d_name);
    if (IsDirectory(Path1))
      n = CopyDirectory(Path1, Path2);
    else
      if (IsRegularFile(Path1))
        n = CopyFile(Path1, Path2);
    free(Path1);
    free(Path2);
  }
  closedir(DirectoryPointer);
  return n;
}

int DeleteFile(char *PathName)
{
  return unlink(PathName);
}

int DeleteDirectory(char *PathName)
{
  return rmdir(PathName);
}