Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move some initialization stuff out of main()

  • Loading branch information...
commit cfd6915b206cc342600339f8ab7c1ea272ea7c69 1 parent 4642e68
discomfitor authored committed
Showing with 43 additions and 35 deletions.
  1. +40 −0 lrzip.c
  2. +1 −0  lrzip.h
  3. +2 −35 main.c
View
40 lrzip.c
@@ -1143,3 +1143,43 @@ void compress_file(rzip_control *control)
free(control->outfile);
}
+
+void initialize_control(rzip_control *control)
+{
+ struct timeval tv;
+ char *eptr; /* for environment */
+
+ memset(control, 0, sizeof(rzip_control));
+ control->msgout = stderr;
+ register_outputfile(control->msgout);
+ control->flags = FLAG_SHOW_PROGRESS | FLAG_KEEP_FILES | FLAG_THRESHOLD;
+ control->suffix = ".lrz";
+ control->compression_level = 7;
+ control->ramsize = get_ram();
+ /* for testing single CPU */
+ control->threads = PROCESSORS; /* get CPUs for LZMA */
+ control->page_size = PAGE_SIZE;
+ control->nice_val = 19;
+
+ /* The first 5 bytes of the salt is the time in seconds.
+ * The next 2 bytes encode how many times to hash the password.
+ * The last 9 bytes are random data, making 16 bytes of salt */
+ if (unlikely(gettimeofday(&tv, NULL)))
+ fatal("Failed to gettimeofday in main\n");
+ control->secs = tv.tv_sec;
+ control->encloops = nloops(control->secs, control->salt, control->salt + 1);
+ get_rand(control->salt + 2, 6);
+
+ /* Get Temp Dir */
+ eptr = getenv("TMP");
+ if (eptr != NULL) {
+ size_t len = strlen(eptr);
+ control->tmpdir = malloc(len+2);
+ if (control->tmpdir == NULL)
+ fatal("Failed to allocate for tmpdir\n");
+ strcpy(control->tmpdir, eptr);
+ if (eptr[len - 2] != '/')
+ eptr[len - 2] = '/'; /* need a trailing slash */
+ eptr[len - 1] = 0;
+ }
+}
View
1  lrzip.h
@@ -41,4 +41,5 @@ void close_tmpoutbuf(rzip_control *control);
void clear_tmpinbuf(rzip_control *control);
inline void clear_tmpinfile(rzip_control *control);
void close_tmpinbuf(rzip_control *control);
+void initialize_control(rzip_control *control);
#endif
View
37 main.c
@@ -353,7 +353,7 @@ static void read_config(rzip_control *control)
int main(int argc, char *argv[])
{
- struct timeval start_time, end_time, tv;
+ struct timeval start_time, end_time;
struct sigaction handler;
double seconds,total_time; // for timers
int c, i;
@@ -362,50 +362,17 @@ int main(int argc, char *argv[])
char *eptr; /* for environment */
control = &controlstaticvariablehaha;
- memset(control, 0, sizeof(rzip_control));
- control->msgout = stderr;
- register_outputfile(control->msgout);
- control->flags = FLAG_SHOW_PROGRESS | FLAG_KEEP_FILES | FLAG_THRESHOLD;
- control->suffix = ".lrz";
- control->outdir = NULL;
- control->tmpdir = NULL;
+ initialize_control(control);
if (strstr(argv[0], "lrunzip"))
control->flags |= FLAG_DECOMPRESS;
else if (strstr(argv[0], "lrzcat"))
control->flags |= FLAG_DECOMPRESS | FLAG_STDOUT;
- control->compression_level = 7;
- control->ramsize = get_ram();
- /* for testing single CPU */
- control->threads = PROCESSORS; /* get CPUs for LZMA */
- control->page_size = PAGE_SIZE;
- control->nice_val = 19;
-
- /* The first 5 bytes of the salt is the time in seconds.
- * The next 2 bytes encode how many times to hash the password.
- * The last 9 bytes are random data, making 16 bytes of salt */
- if (unlikely(gettimeofday(&tv, NULL)))
- fatal("Failed to gettimeofday in main\n");
- control->secs = tv.tv_sec;
- control->encloops = nloops(control->secs, control->salt, control->salt + 1);
- get_rand(control->salt + 2, 6);
-
/* generate crc table */
CrcGenerateTable();
- /* Get Temp Dir */
- eptr = getenv("TMP");
- if (eptr != NULL) {
- control->tmpdir = malloc(strlen(eptr)+2);
- if (control->tmpdir == NULL)
- fatal("Failed to allocate for tmpdir\n");
- strcpy(control->tmpdir, eptr);
- if (strcmp(eptr+strlen(eptr) - 1, "/")) /* need a trailing slash */
- strcat(control->tmpdir, "/");
- }
-
/* Get Preloaded Defaults from lrzip.conf
* Look in ., $HOME/.lrzip/, /etc/lrzip.
* If LRZIP=NOCONFIG is set, then ignore config
Please sign in to comment.
Something went wrong with that request. Please try again.