File: lin-file.c

package info (click to toggle)
egoboo 2.22-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,640 kB
  • ctags: 2,570
  • sloc: ansic: 23,989; makefile: 94; sh: 83
file content (107 lines) | stat: -rw-r--r-- 2,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// lin-file.c

// Egoboo, Copyright (C) 2000 Aaron Bishop

#include "egoboo.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/dir.h>

char command[1024];
FILE *DirFiles;
char DirRead[1024];

//File Routines-----------------------------------------------------------
void make_directory(char *dirname)
{
    // ZZ> This function makes a new directory
    snprintf(command, sizeof(command), "mkdir -p %s > /dev/null 2>&1\n",dirname);
    system(command);
}

void delete_file(char *filename)
{
    // ZZ> This function deletes a file
    snprintf(command, sizeof(command), "rm -f %s > /dev/null 2>&1\n",filename);
    system(command);
}

void copy_file(char *source, char *dest)
{
    // ZZ> This function copies a file on the local machine
    snprintf(command, sizeof(command), "cp -f %s %s > /dev/null 2>&1\n",source,dest);
    system(command);
}

void delete_directory(char *dirname)
{
    // ZZ> This function deletes all files in a directory,
    //     and the directory itself
    snprintf(command, sizeof(command), "rm -rf %s > /dev/null 2>&1\n",dirname);
    system(command);
}

void copy_directory(char *dirname, char *todirname)
{
    // ZZ> This function copies all files in a directory
    snprintf(command, sizeof(command), "cp -fr %s %s > /dev/null 2>&1\n",dirname,todirname);
    system(command);
}

void empty_import_directory(char* home)
{
    // ZZ> This function deletes all the TEMP????.OBJ subdirectories in the IMPORT directory
    snprintf(command, sizeof(command), "rm -rf %s/temp*.obj > /dev/null 2>&1\n", home);
    system(command);
}

// Read the first directory entry
char *DirGetFirst(char *search)
{
  snprintf(command, sizeof(command), "find %s -maxdepth 0 -printf \"%%f\\n\"  ",search);
  DirFiles=popen(command,"r");
  if(!feof(DirFiles))
  {
    fscanf(DirFiles,"%s\n",DirRead);
    return(DirRead);
  }
  else
  {
    return(NULL);
  }
}

// Read the next directory entry (NULL if done)
char *DirGetNext(void)
{
  if(!feof(DirFiles))
  { 
    fscanf(DirFiles,"%s\n",DirRead);
    return(DirRead);
  }
  else
  {
    return(NULL);
  }
}

// Close anything left open
void DirClose()
{
  fclose(DirFiles);
}

int ClockGetTick()
{
  return(clock());
}

int DirGetAttrib(char *fromdir)
{
  int tmp;
#define FILE_ATTRIBUTE_DIRECTORY 0x10
#define FILE_ATTRIBUTE_NORMAL 0x0
#define FILE_ATTRIBUTE_ERROR 0xffffffff

  return(0);
}