From 17bf3359226c5efc2636f05ae1945306f92db3c1 Mon Sep 17 00:00:00 2001 From: J. Ali Harlow Date: Fri, 9 Jan 2009 15:28:50 +0000 Subject: [PATCH] Use CSIDL on MS-Windows platforms instead of FHS paths. --- configure.ac | 2 +- librazor/root.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 6527b25..5d4b55d 100644 --- a/configure.ac +++ b/configure.ac @@ -36,7 +36,7 @@ AC_MSG_CHECKING([for Microsoft Windows native API]) case $host_os in *mingw*) AC_DEFINE([MSWIN_API], 1, [Define to 1 to use Microsoft Windows native API.]) - EXTRA_LIBS='-lws2_32' + EXTRA_LIBS='-lshell32 -lws2_32' mswin_api=yes;; *) mswin_api=no;; esac diff --git a/librazor/root.c b/librazor/root.c index 05bd231..87fb2d5 100644 --- a/librazor/root.c +++ b/librazor/root.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc + * Copyright (C) 2009 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" + #include #include #include @@ -27,6 +30,9 @@ #include #include #include +#ifdef MSWIN_API +#include +#endif #include "razor.h" #include "razor-internal.h" @@ -36,7 +42,12 @@ static const char system_repo_details_filename[] = "system-details.rzdb"; static const char system_repo_files_filename[] = "system-files.rzdb"; static const char next_repo_filename[] = "system-next.rzdb"; -static const char razor_root_path[] = "/var/lib/razor"; +#ifdef MSWIN_API +#define RAZOR_ROOT_PATH NULL +#else +#define RAZOR_ROOT_PATH "/var/lib/razor" +#endif +static const char *razor_root_path = RAZOR_ROOT_PATH; struct razor_root { struct razor_set *system; @@ -47,6 +58,21 @@ struct razor_root { char new_path[PATH_MAX]; }; +static void +razor_root_init(void) +{ +#ifdef MSWIN_API + static char root_path[MAX_PATH]; + if (!razor_root_path) { + SHGetFolderPath(NULL, + CSIDL_COMMON_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, 0, + root_path); + strcat(root_path, "\\Razor"); + razor_root_path = root_path; + } +#endif +} + RAZOR_EXPORT int razor_root_create(const char *root) { @@ -56,6 +82,7 @@ razor_root_create(const char *root) assert (root != NULL); + razor_root_init(); if (root[0] == '\0') { /* root is file system root */ } else if (stat(root, &buf) < 0) { @@ -112,6 +139,7 @@ razor_root_open(const char *root) assert (root != NULL); + razor_root_init(); image = malloc(sizeof *image); if (image == NULL) return NULL; @@ -166,6 +194,7 @@ razor_root_open_read_only(const char *root) assert (root != NULL); + razor_root_init(); snprintf(path, sizeof path, "%s%s/%s", root, razor_root_path, system_repo_filename); snprintf(details_path, sizeof details_path, @@ -216,6 +245,7 @@ razor_root_update(struct razor_root *root, struct razor_set *next) assert (root != NULL); assert (next != NULL); + razor_root_init(); razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN); root->next = next; -- 1.7.1