2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) 2008 Liam Girdwood
20 #include <sys/types.h>
26 #include <libastrodb/library.h>
27 #include <libastrodb/adbstdio.h>
29 #define PATH_SIZE 1024
31 enum astrodb_msg_level adb_msg_level
= ADB_MSG_INFO
;
33 static char *dirs
[] = {
45 static int create_lib_local_dirs(char *location
)
48 struct stat stat_info
;
51 /* create <path>/lnc/ */
52 bzero(dir
, PATH_SIZE
);
53 strncat(dir
, location
, PATH_SIZE
);
54 if (stat(location
, &stat_info
) < 0) {
55 if ((ret
= mkdir(dir
, S_IRWXU
| S_IRWXG
)) < 0) {
61 for (i
= 0; i
< astrodb_size(dirs
); i
++) {
62 bzero(dir
, PATH_SIZE
);
63 strncat(dir
, location
, PATH_SIZE
);
64 strncat(dir
, dirs
[i
], PATH_SIZE
);
65 if (stat(dir
, &stat_info
) < 0) {
66 if ((ret
= mkdir(dir
, S_IRWXU
| S_IRWXG
)) < 0) {
75 /*! \fn astrodb_library* astrodb_open_library(char* remote, char* local)
76 * \param local Local library repository location
77 * \param remote Remote repository location
78 * \returns A astrodb_library object or NULL on failure
80 * Initialises a CDS library structure on disk at location specified.
82 * This typically only needs to be called once per program.
85 struct astrodb_library
*astrodb_open_library(char *remote
, char *local
)
87 struct astrodb_library
*lib
= NULL
;
93 lib
= (struct astrodb_library
*) malloc(sizeof(struct astrodb_library
));
96 bzero(lib
, sizeof(struct astrodb_library
));
98 err
= create_lib_local_dirs(local
);
100 astrodb_error("failed to create local lib dir %s %d\n",
106 lib
->local
= strdup(local
);
107 if (lib
->local
== NULL
)
109 lib
->remote
= strdup(remote
);
110 if (lib
->remote
== NULL
)
122 /*! \fn void astrodb_close_library(astrodb_library* lib)
123 * \param lib Library to free
125 * Free's all library resources.
127 void astrodb_close_library(struct astrodb_library
* lib
)
134 void astrodb_set_msg_level(enum astrodb_msg_level level
)
136 adb_msg_level
= level
;