]> git.saurik.com Git - wxWidgets.git/blame - utils/Install/packace/uac_crt.c
added default style wxFRAME_TOOL_WINDOW to creation
[wxWidgets.git] / utils / Install / packace / uac_crt.c
CommitLineData
f6bcfd97
BP
1/* ------------------------------------------------------------------------ */
2/* */
3/* Creates/Replaces files or directories. */
4/* */
5/* ------------------------------------------------------------------------ */
6
7#include "os.h"
8
9#include <stdlib.h>
10#include <fcntl.h> // AMIGA: open()
11#include <stdio.h> // pipeit() remove()
12#include <string.h> // strncpy()
13#include <sys/types.h>
14#include <sys/stat.h> // struct stat
15#include <string.h>
16
17
18#if defined(DOS) || defined(WINNT) || defined(WIN16)
19 #include <io.h> // access()
20#endif
21#if defined(__IBMC__)
22 #include <direct.h>
23#endif
24
25#define DIRSEP '\\'
26
27#include "attribs.h"
28#include "globals.h"
29#include "uac_crt.h"
30#include "uac_sys.h"
31
32/* gets file name from header
33 */
34CHAR *ace_fname(CHAR * s, thead * head, INT nopath)
35{
36 INT i;
37 char *cp;
38
39 strncpy(s, (CHAR *)(*(tfhead *) head).FNAME, i = (*(tfhead *) head).FNAME_SIZE);
40 s[i] = 0;
41
42 if (nopath)
43 {
44 cp=strrchr(s, '\\');
45 if (cp)
46 memmove(s, cp+1, strlen(cp));
47 }
48
49 return s;
50}
51
52void check_ext_dir(CHAR * f) // checks/creates path of file
53{
54 CHAR *cp,
55 d[PATH_MAX];
56 INT i;
57
58 d[0] = 0;
59
60 for (;;)
61 {
62 if ((cp = (CHAR *) strchr(&f[strlen(d) + 1], DIRSEP))!=NULL)
63 {
64 i = cp - f;
65 strncpy(d, f, i);
66 d[i] = 0;
67 }
68 else
69 return;
70
71 if (!fileexists(d))
72#if (defined(__OS2__) && !defined(__EMX__)) || (defined(WINNT) && !defined(__CYGWIN__))
73 if (mkdir(d))
74#else
75 if (mkdir(d, 0))
76#endif
77 {
78 f_err = ERR_WRITE;
79 pipeit("\n Error while creating directory.\n");
80 }
81 }
82}
83
84INT ovr_delete(CHAR * n) // deletes directory or file
85{
86 if (remove(n) && rmdir(n))
87 {
88 pipeit("\n Could not delete file or directory. Access denied.\n");
89 return (1);
90 }
91 return (0);
92}
93
94INT create_dest_file(CHAR * file, INT a) // creates file or directory
95{
96 INT han,
97 i = 0,
98 ex = fileexists(file);
99 struct stat st;
100
101 check_ext_dir(file);
102 if (f_err)
103 return (-1);
104 if (a & _A_SUBDIR)
105 { // create dir or file?
106 if (ex)
107 stat(file, &st);
108#if (defined(__OS2__) && !defined(__EMX__)) || (!defined(__CYGWIN__) && defined(WINNT))
109 if ((!ex && mkdir(file)) || (ex && (st.st_mode & S_IFDIR)))
110#else
111 if ((!ex && mkdir(file, 0)) || (ex && (st.st_mode & S_IFDIR)))
112#endif
113 {
114 pipeit("\n Could not create directory.\n");
115 return (-1);
116 }
117#ifdef DOS
118 _dos_setfileattr(file, a); // set directory attributes
119#endif
120 return (-1);
121 }
122 else
123 {
124 if (ex)
125 { // does the file already exist
126 if (!f_ovrall)
127 {
128 i = wrask("Overwrite existing file?"); // prompt for overwrite
129 f_ovrall = (i == 1);
130 if (i == 3)
131 f_err = ERR_USER;
132 }
133 if ((i && !f_ovrall) || ovr_delete(file))
134 return (-1); // delete?
135 }
136#if defined(__OS2_) || defined(__EMX__) || defined(WIN32)
137 if ((han = open(file, O_WRONLY | O_TRUNC | O_CREAT | O_BINARY,
138 S_IREAD | S_IWRITE | S_IEXEC | S_IDELETE |
139 S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH )) < 0)
140#else
141 if ((han = open(file, O_WRONLY | O_TRUNC | O_CREAT,
142 S_IREAD | S_IWRITE | S_IEXEC | S_IDELETE |
143 S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH )) < 0)
144#endif
145 pipeit("\n Could not create destination file.\n");
146 return (han);
147 }
148}
149