42 #define JAVA_DIR "java" 43 #define COPY_BUFFER_SIZE 1024 45 #define SEPERATOR '\\' 50 #define GETMSG(msgnum) util_get_message(Msg_catalog, MSG_SET_LOADJAVA, msgnum) 52 static int filecopy (
const char *fn_src,
const char *fn_dst);
73 badchar = util_check_dbname (name);
78 fprintf (stderr, msg, badchar, name);
92 filecopy (
const char *fn_src,
const char *fn_dst)
101 fh_src = fopen (fn_src,
"rb");
104 fprintf (stderr,
"'%s' cannot open.\n", fn_src);
110 fh_dst = fopen (fn_dst,
"r");
114 fprintf (stdout,
"'%s' is exist. overwrite? (y/n): ", fn_dst);
116 if (c !=
'Y' && c !=
'y')
119 fprintf (stdout,
"loadjava is canceled\n");
124 fh_dst = fopen (fn_dst,
"w+b");
128 fprintf (stderr,
"'%s' cannot open.\n", fn_dst);
144 retval = ferror (fh_src);
149 if (fwrite (buff, 1, bytesr, fh_dst) != bytesr)
151 retval = ferror (fh_dst);
172 fprintf (stderr,
"Usage: loadjava [OPTION] database-name java-class-file\n");
173 fprintf (stderr,
"Options:\n-y\t%s\n",
184 int status = EXIT_FAILURE;
188 char *java_dir =
NULL;
189 char *class_file_name =
NULL;
190 char *class_file_path =
NULL;
191 struct option loadjava_option[] = {
192 {
"overwrite", 0, 0,
'y'},
204 int option_index = 0;
207 option_key =
getopt_long (argc, argv,
"y", loadjava_option, &option_index);
208 if (option_key == -1)
246 fprintf (stderr,
"database '%s' does not exist.\n",
Dbname);
252 fprintf (stderr,
"out of memory\n");
257 if (mkdir (java_dir, 0744) != 0 && errno != EEXIST)
259 fprintf (stderr,
"can't create directory: '%s'\n", java_dir);
270 if ((class_file_path = (
char *) malloc (
strlen (java_dir) +
strlen (class_file_name) + 2)) ==
NULL)
272 fprintf (stderr,
"out of memory\n");
276 sprintf (class_file_path,
"%s%c%s", java_dir,
SEPERATOR, class_file_name);
279 fprintf (stderr,
"loadjava fail: file operation error\n");
283 status = EXIT_SUCCESS;
292 free (class_file_path);
DB_INFO * cfg_find_db(const char *db_name)
static int check_dbname(const char *name)
static int Force_overwrite
int getopt_long(int, char *const *, const char *, const struct option *, int *)
static int filecopy(const char *fn_src, const char *fn_dst)
static void error(const char *msg)
static char * Program_name
char * msgcat_message(int cat_id, int set_id, int msg_id)
int main(int argc, char *argv[])
#define MSGCAT_CATALOG_UTILS