Skip to content

Commit

Permalink
Merge pull request #11 from mach-kernel/clean-preprocs
Browse files Browse the repository at this point in the history
Clean preprocs
  • Loading branch information
mach-kernel authored Mar 1, 2018
2 parents a9dd04a + 26e4c01 commit e5e89a3
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 78 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Any and all contributions are welcome. Included is also a `cadius.pro` file you

## Changelog

#### 1.3.2
- Maintenance release / macro cleanup

#### 1.3.1
- Resolves timestamp bugs in [#10](https://github.com/mach-kernel/cadius/issues/10). Thanks, @a2-4am!

Expand Down
8 changes: 4 additions & 4 deletions Src/Dc_Shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#include <string.h>
#include <ctype.h>

#if IS_WINDOWS
#include <malloc.h>
#endif

#include "Dc_Shared.h"
#include "os/os.h"
#include "Dc_Memory.h"

#ifdef IS_WINDOWS
#include <malloc.h>
#endif

/***************************************************************/
/* LoadBinaryFile() : Récupération des données d'un fichier. */
/***************************************************************/
Expand Down
12 changes: 6 additions & 6 deletions Src/Prodos_Extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdlib.h>
#include <string.h>

#if IS_WINDOWS
#ifdef IS_WINDOWS
#include <malloc.h>
#endif

Expand Down Expand Up @@ -313,7 +313,7 @@ static int CreateOutputFile(struct prodos_file *current_file, char *output_direc
/** Ajustement des Dates **/
os_SetFileCreationModificationDate(file_data_path,current_file->entry);

#if IS_WINDOWS
#ifdef IS_WINDOWS
/** Change la visibilité du fichier **/
os_SetFileAttribute(
file_data_path, ((current_file->entry->access & 0x04) == 0x04) ? SET_FILE_HIDDEN : SET_FILE_VISIBLE
Expand All @@ -340,7 +340,7 @@ static int CreateOutputFile(struct prodos_file *current_file, char *output_direc
/** Ajustement des Dates **/
os_SetFileCreationModificationDate(file_resource_path,current_file->entry);

#if IS_WINDOWS
#ifdef IS_WINDOWS
/** Change la visibilité du fichier **/
os_SetFileAttribute(
file_resource_path,
Expand Down Expand Up @@ -387,14 +387,14 @@ static void SetFileInformation(char *file_information_path, struct prodos_file *
/* Créer le fichier FileInformation */
CreateBinaryFile(file_information_path,(unsigned char *)local_buffer,(int)strlen(local_buffer));

#if IS_WINDOWS
#ifdef IS_WINDOWS
/* Rendre le fichier invisible */
os_SetFileAttribute(file_information_path, SET_FILE_HIDDEN);
return;
#endif
}

#if IS_WINDOWS
#ifdef IS_WINDOWS
/* Rendre le fichier visible */
os_SetFileAttribute(file_information_path, SET_FILE_VISIBLE);
#endif
Expand Down Expand Up @@ -434,7 +434,7 @@ static void SetFileInformation(char *file_information_path, struct prodos_file *
mem_free_list(nb_line,line_tab);

/* Rendre le fichier invisible */
#if IS_WINDOWS
#ifdef IS_WINDOWS
os_SetFileAttribute(file_information_path, SET_FILE_HIDDEN);
#endif
}
Expand Down
54 changes: 48 additions & 6 deletions Src/os/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,52 @@
*
*/

#if IS_WINDOWS
#define BUILD_WIN32 1
#include "win32.c"
#else
#define BUILD_POSIX 1
#include "posix.c"
#include "os.h"

/**
* Delete file at path
* @brief os_DeleteFile
* @param file_path
*/
void os_DeleteFile(char *file_path)
{
#ifdef BUILD_WINDOWS
os_SetFileAttribute(file_path, SET_FILE_VISIBLE);
#endif
unlink(file_path);
}

/**
* Recursively (if necessary) creates a directory. This should work
* on both POSIX and the classic Win32 C runtime, but will not work
* with UWP.
*
* @brief os_CreateDirectory Create a directory
* @param directory char *directory
* @return
*/
int os_CreateDirectory(char *directory)
{
int error = 0;
struct stat dirstat;

char *dir_tokenize = strdup(directory);

char *buffer = calloc(1, 1024);
char *token = strtok(dir_tokenize, FOLDER_CHARACTER);

while (token) {
if (strlen(buffer) + strlen(token) > 1024) return(-1);
strcat(buffer, token);

if (stat(buffer, &dirstat) != 0)
error = my_mkdir(buffer);
else if (!S_ISDIR(dirstat.st_mode))
error = my_mkdir(buffer);

strcat(buffer, FOLDER_CHARACTER);
token = strtok(NULL, FOLDER_CHARACTER);
}

return error;
}
77 changes: 19 additions & 58 deletions Src/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

#pragma once

#define IS_WINDOWS defined (_WIN32) || defined(_WIN64)
#define IS_DARWIN defined(__APPLE__) || defined(__MACH__)
#define IS_LINUX defined(__linux__)
#if defined(_WIN32) || defined(_WIN64)
#define BUILD_WINDOWS 1
#else
#define BUILD_POSIX 1
#endif

#include <errno.h>
#include <fcntl.h>
Expand All @@ -24,7 +26,17 @@
#include <sys/types.h>
#include <time.h>

#if IS_WINDOWS
#ifdef BUILD_POSIX

#define FOLDER_CHARACTER "/"

#include <dirent.h>
#include <utime.h>

#endif

#ifdef BUILD_WINDOWS

#pragma warning(disable:4996)

#define FOLDER_CHARACTER "\\"
Expand All @@ -34,14 +46,9 @@
#include <direct.h>
#include <windows.h>

#else
#define FOLDER_CHARACTER "/"

#include <dirent.h>
#include <utime.h>

#endif


#if !defined(S_ISDIR) && defined(S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
Expand All @@ -53,55 +60,9 @@
#include "../Dc_Prodos.h"
#include "../Dc_Memory.h"

/**
* Delete file at path
* @brief os_DeleteFile
* @param file_path
*/
static void os_DeleteFile(char *file_path)
{
#if IS_WINDOWS
os_SetFileAttribute(file_path,SET_FILE_VISIBLE);
#endif
unlink(file_path);
}

/**
* Recursively (if necessary) creates a directory. This should work
* on both POSIX and the classic Win32 C runtime, but will not work
* with UWP.
*
* @brief os_CreateDirectory Create a directory
* @param directory char *directory
* @return
*/
static int os_CreateDirectory(char *directory)
{
int error = 0;
struct stat dirstat;

char *dir_tokenize = strdup(directory);

char *buffer = calloc(1, 1024);
char *token = strtok(dir_tokenize, FOLDER_CHARACTER);

while (token) {
if (strlen(buffer) + strlen(token) > 1024) return(-1);
strcat(buffer, token);

if (stat(buffer, &dirstat) != 0)
error = my_mkdir(buffer);
else if (!S_ISDIR(dirstat.st_mode))
error = my_mkdir(buffer);

strcat(buffer, FOLDER_CHARACTER);
token = strtok(NULL, FOLDER_CHARACTER);
}

return error;
}

int os_GetFolderFiles(char *,char *);
int os_CreateDirectory(char *directory);
void os_DeleteFile(char *file_path);
void os_SetFileCreationModificationDate(char *,struct file_descriptive_entry *);
void os_GetFileCreationModificationDate(char *,struct prodos_file *);
void os_SetFileAttribute(char *,int);
Expand Down
4 changes: 2 additions & 2 deletions Src/os/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*
*/

#if BUILD_POSIX
#include "os.h"

#include "os.h"
#ifdef BUILD_POSIX

/**
* Creates a directory. The POSIX compliant one requires a mask,
Expand Down
4 changes: 2 additions & 2 deletions Src/os/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*
*/

#if BUILD_WIN32

#include "os.h"

#ifdef BUILD_WINDOWS

/**
* Win32 C runtime get contents of directory.
*
Expand Down

0 comments on commit e5e89a3

Please sign in to comment.