From: <ba...@us...> - 2007-02-14 17:38:59
|
Revision: 440 http://svn.sourceforge.net/omc/?rev=440&view=rev Author: bartw Date: 2007-02-14 09:38:58 -0800 (Wed, 14 Feb 2007) Log Message: ----------- re-added fileTools Modified Paths: -------------- omccmpi/trunk/src/include/omc/Makefile.am omccmpi/trunk/src/lib/omc/Makefile.am Added Paths: ----------- omccmpi/trunk/src/include/omc/fileTools.h omccmpi/trunk/src/lib/omc/fileTools.c Removed Paths: ------------- omccmpi/trunk/src/include/omc/Makefile.in Modified: omccmpi/trunk/src/include/omc/Makefile.am =================================================================== --- omccmpi/trunk/src/include/omc/Makefile.am 2007-02-14 17:17:15 UTC (rev 439) +++ omccmpi/trunk/src/include/omc/Makefile.am 2007-02-14 17:38:58 UTC (rev 440) @@ -8,6 +8,7 @@ exec.h \ ioUtils.h \ modifyFile.h \ + fileTools.h \ string.h \ linuxProcUtils.h \ cmpiUtils.h \ Deleted: omccmpi/trunk/src/include/omc/Makefile.in =================================================================== --- omccmpi/trunk/src/include/omc/Makefile.in 2007-02-14 17:17:15 UTC (rev 439) +++ omccmpi/trunk/src/include/omc/Makefile.in 2007-02-14 17:38:58 UTC (rev 440) @@ -1,406 +0,0 @@ -# Makefile.in generated by automake 1.9.6 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -top_builddir = ../../.. -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = @INSTALL@ -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -subdir = src/include/omc -DIST_COMMON = $(pkginclude_HEADERS) $(srcdir)/Makefile.am \ - $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -SOURCES = -DIST_SOURCES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; -am__installdirs = "$(DESTDIR)$(pkgincludedir)" -pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER) -HEADERS = $(pkginclude_HEADERS) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -pkgincludedir = $(includedir)/omccmpi -ACLOCAL = @ACLOCAL@ -ALLOCA = @ALLOCA@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ -AMTAR = @AMTAR@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CP = @CP@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -ECHO = @ECHO@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LDFLAGS = @LDFLAGS@ -LEX = @LEX@ -LEXLIB = @LEXLIB@ -LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBTOOL = @LIBTOOL@ -LN_S = @LN_S@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MV = @MV@ -OBJEXT = @OBJEXT@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -RANLIB = @RANLIB@ -RM = @RM@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -YACC = @YACC@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -ac_ct_STRIP = @ac_ct_STRIP@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ -am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -datadir = @datadir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -pkginclude_HEADERS = \ - base.h \ - exec.h \ - ioUtils.h \ - modifyFile.h \ - string.h \ - linuxProcUtils.h \ - cmpiUtils.h \ - cmpiSimpleAssoc.h \ - cmpiTimeServiceUtils.h \ - ntpServer.h - -all: all-am - -.SUFFIXES: -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/include/omc/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/include/omc/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -distclean-libtool: - -rm -f libtool -uninstall-info-am: -install-pkgincludeHEADERS: $(pkginclude_HEADERS) - @$(NORMAL_INSTALL) - test -z "$(pkgincludedir)" || $(mkdir_p) "$(DESTDIR)$(pkgincludedir)" - @list='$(pkginclude_HEADERS)'; for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - f=$(am__strip_dir) \ - echo " $(pkgincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgincludedir)/$$f'"; \ - $(pkgincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgincludedir)/$$f"; \ - done - -uninstall-pkgincludeHEADERS: - @$(NORMAL_UNINSTALL) - @list='$(pkginclude_HEADERS)'; for p in $$list; do \ - f=$(am__strip_dir) \ - echo " rm -f '$(DESTDIR)$(pkgincludedir)/$$f'"; \ - rm -f "$(DESTDIR)$(pkgincludedir)/$$f"; \ - done - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkdir_p) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ - if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(HEADERS) -installdirs: - for dir in "$(DESTDIR)$(pkgincludedir)"; do \ - test -z "$$dir" || $(mkdir_p) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic clean-libtool mostlyclean-am - -distclean: distclean-am - -rm -f Makefile -distclean-am: clean-am distclean-generic distclean-libtool \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: install-pkgincludeHEADERS - -install-exec-am: - -install-info: install-info-am - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-generic mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-info-am uninstall-pkgincludeHEADERS - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool ctags distclean distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-exec install-exec-am install-info \ - install-info-am install-man install-pkgincludeHEADERS \ - install-strip installcheck installcheck-am installdirs \ - maintainer-clean maintainer-clean-generic mostlyclean \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-info-am \ - uninstall-pkgincludeHEADERS - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: Added: omccmpi/trunk/src/include/omc/fileTools.h =================================================================== --- omccmpi/trunk/src/include/omc/fileTools.h (rev 0) +++ omccmpi/trunk/src/include/omc/fileTools.h 2007-02-14 17:38:58 UTC (rev 440) @@ -0,0 +1,104 @@ +/******************************************************************************* +* Copyright (C) 2005, 2006 Novell, Inc. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* - Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* - Neither the name of Novell, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +******************************************************************************/ + + +#ifndef OMCFILETOOLS_H_GUARD__ +#define OMCFILETOOLS_H_GUARD__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct stat; + +/** + * Return the name of the directory containing the file (or + * directory) referenced by path. + * + * @param path The path + * + * @return The directory containing the file. The caller is + * responsible to free the buffer returned. + */ +char* omc_dirname(const char* path); + +/** + * Struct containing the six keys of CIM file classes. + * (CIM_LogicalFile and children) + */ +typedef struct omcFileKeys_ +{ + char * CSCreationClassName; + char * CSName; + char * CreationClassName; + char * FSCreationClassName; + char * FSName; + char * Name; +} omcFileKeys; + +/** + * Free a omcFileKeys structure and the pointers contained + * therein. + * + * @param fk pointer to the omcFileKeys structure to be freed. + */ +void omcFileKeys_free(omcFileKeys* fk); + +/** + * Determine the keys for the CIM instance representing a given + * file. + * @param path The full path to the file + * + * @return A pointer to an omcFileKeys structure. The caller is + * responsible to free this with a call to + * omcFileKeys_free(). + */ +omcFileKeys* omcGetKeysForFile(const char* path); + +/** + * Determine the keys for the CIM instance representing a given + * file. Use this version if you already have a stat for the + * file and wish to avoid an aditional stat. + * + * @param path The full path to the file + * @param st A stat structure for the file obtained from stat() + * + * @return A pointer to an omcFileKeys structure. The caller is + * responsible to free this with a call to + * omcFileKeys_free(). + */ +omcFileKeys* omcGetKeysForFileStat(const char* path, struct stat* st); + +#ifdef __cplusplus +} +#endif + +#endif Modified: omccmpi/trunk/src/lib/omc/Makefile.am =================================================================== --- omccmpi/trunk/src/lib/omc/Makefile.am 2007-02-14 17:17:15 UTC (rev 439) +++ omccmpi/trunk/src/lib/omc/Makefile.am 2007-02-14 17:38:58 UTC (rev 440) @@ -21,4 +21,5 @@ modifyFile.c \ string.c \ linuxProcUtils.c \ +fileTools.c \ ntpServer.c Added: omccmpi/trunk/src/lib/omc/fileTools.c =================================================================== --- omccmpi/trunk/src/lib/omc/fileTools.c (rev 0) +++ omccmpi/trunk/src/lib/omc/fileTools.c 2007-02-14 17:38:58 UTC (rev 440) @@ -0,0 +1,201 @@ +/******************************************************************************* +* Copyright (C) 2005, 2006 Novell, Inc. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* - Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* - Neither the name of Novell, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +******************************************************************************/ + + +#include "omc/fileTools.h" +//#include "omccmpi/string.h" +//#include "omccmpi/ioUtils.h" +//#include "string.h" +//#include "ioUtils.h" +#include <libgen.h> +#include "omc/string.h" +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include <stdlib.h> +#include <stdio.h> + +char* omc_dirname(const char* path) +{ + char* tmp = strdup(path); + char* rv = dirname(tmp); + if (rv == NULL) + { + free(tmp); + } + return rv; +} + +void omcFileKeys_free(omcFileKeys* fk) +{ + if (fk == NULL) + { + return; + } + //free(fk->CSCreationClassName); // not malloc'd + free(fk->CSName); + //free(fk->CreationClassName); // not malloc'd + free(fk->FSCreationClassName); + free(fk->FSName); + free(fk->Name); + free(fk); +} + +omcFileKeys* omcGetKeysForFile(const char* path) +{ + struct stat st; + if (lstat(path, &st) != 0) + { + return NULL; + } + return omcGetKeysForFileStat(path, &st); +} + +omcFileKeys* omcGetKeysForFileStat(const char* path, struct stat* st) +{ + omcFileKeys* rv = (omcFileKeys*)malloc(sizeof(omcFileKeys)); + memset(rv, 0, sizeof(omcFileKeys)); + if (S_ISREG(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxDataFile"; + } else if (S_ISDIR(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxDirectory"; + } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxDeviceFile"; + } else if (S_ISFIFO(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxFIFOPipeFile"; + } else if (S_ISLNK(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxSymbolicLink"; + } else + { + free(rv); + return NULL; + } + rv->Name = strdup(path); + rv->CSCreationClassName = "OMC_LinuxUnitaryComputerSystem"; + rv->CSName = (char*)malloc(256); + gethostname(rv->CSName, 256); + FILE* mounts = fopen("/proc/mounts", "r"); + if (mounts == NULL) + { + omcFileKeys_free(rv); + return NULL; + } + char* line = NULL; + char* p = NULL; + size_t bfrLen = 0; + for(p = omcReadLine(mounts, &line,&bfrLen); p; p = omcReadLine(mounts, &line,&bfrLen )) + { + int count = omcStrTokenCount(line, " \t\r\n"); + if (count != 6) + { + continue; + } + size_t numElems = 0; + char** strs = omcStrTokenize(line, " \t\r\n", &numElems); + if (strs == NULL) + { + continue; + } + if (strs[1][0] != '/') + { + free(strs); + continue; + } + if (strs[1][1] == 0 && strcmp(strs[0], "rootfs") == 0) + { + /* skip rootfs junk */ + free(strs); + continue; + } + struct stat dst; + if (stat(strs[1], &dst) != 0) + { + free(strs); + continue; + } + if (st->st_dev == dst.st_dev) + { + rv->FSName = strdup(strs[0]); + char* fstype = strs[2]; + if (strcmp(fstype, "ext2") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxExt2FileSystem"); + } else if (strcmp(fstype, "ext3") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxExt3FileSystem"); + } else if (strcmp(fstype, "reiserfs") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxReiserFileSystem"); + } else if (strcmp(fstype, "nfs") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxNFS"); + } else if (strcmp(fstype, "cifs") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxCIFS"); /* TODO CIM class doesn't exist yet */ + } + else + { + int len = snprintf(NULL, 0, "Unknown:%s", fstype); + if (len > 0) + { + rv->FSCreationClassName = (char*)malloc(len + 1); + snprintf(rv->FSCreationClassName, len+1, "Unknown:%s", fstype); + } + else + { + rv->FSCreationClassName = strdup("Unknown"); + } + } + } + free(strs); + if (rv->FSName != NULL) + { + break; + } + } + if (line) + { + free(line); + } + fclose(mounts); + return rv; + +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-05-07 20:14:21
|
Revision: 598 http://omc.svn.sourceforge.net/omc/?rev=598&view=rev Author: jcarey Date: 2008-05-07 13:14:16 -0700 (Wed, 07 May 2008) Log Message: ----------- Added string array/buffer functions Modified Paths: -------------- omccmpi/trunk/src/include/omc/string.h omccmpi/trunk/src/lib/omc/string.c Modified: omccmpi/trunk/src/include/omc/string.h =================================================================== --- omccmpi/trunk/src/include/omc/string.h 2008-05-05 15:10:58 UTC (rev 597) +++ omccmpi/trunk/src/include/omc/string.h 2008-05-07 20:14:16 UTC (rev 598) @@ -165,6 +165,133 @@ */ char** omcStrTokenize(const char* src, const char* delims, size_t* numberOfElements); +/** + * omcStrBuf represent a dynamic string buffer. It is created/destroyed/manipulted + * by the omcStrBuf_xxx set of functions that follow. + */ +typedef struct { + size_t buf_len; + size_t str_len; + char* bfr; +} omcStrBuf; + +/** + * Create an initialized omcStrBuf object. + * @return A pointer to an initialized omcStrBuf object. This pointer must + * eventually be destroyed by calling omcStrBuf_destroy. This function will + * return NULL on failure. + */ +omcStrBuf* omcStrBuf_create(); + +/** + * Destroy an omcStrBuf object and release the allocated memory associated with it. + * @param psbuf A pointer to the omcStrBuf object to be destroyed. + * @return 0 for success. Otherwise -1 + */ +int omcStrBuf_destroy(omcStrBuf* psbuf); + +/** + * Append a string to the string represented by a given omcStrBuf object. + * @param psbuf The omcStrBuf object to append the string to. + * @param str A the string to append to the given omcStrBuf object. + * @param n The number of character of str to append to the given + * omcStrBuf object. If this parameter is 0, then all of str will + * be appended. + * @return A pointer to the modified string or NULL on failure. + */ +const char* omcStrBuf_cat(omcStrBuf* psbuf, const char* str, size_t n); + +/** + * Set the omcStrBuf object to a given string. + * @param psbuf The omcStrBuf object to set. + * @param str A the string to set the given omcStrBuf object to. + * @param n The number of character of str to set the given + * omcStrBuf object to. If this parameter is 0, then all of str will + * be used. + * @return A pointer to the string represented by the omcStrBuf object, + * or NULL on failure. + */ +const char* omcStrBuf_set(omcStrBuf* psbuf, const char* str, size_t n); + +/** + * Reset a given omcStrBuf object to an empty string. + * @param psbuf The omcStrBuf object to reset. + * @return 0 on success. Otherwise -1. + */ +int omcStrBuf_reset(omcStrBuf* psbuf); + +/** + * omcStrArray represent a dynamic string array. It is created/destroyed/manipulated + * by the omcStrArray_xxx set of functions that follow. + */ +typedef struct { + size_t num_strings; + size_t buf_size; + char** strs; +} omcStrArray; + +/** + * Create/initialize an omcStrArray object. + * @return A pointer to the newly created/initialized omcStrArray object. + * This pointer will be used in all subsequent calls to omcStrArray_xxx + * functions and must eventually be passed to omcStrArray_destroy() + */ +omcStrArray* omcStrArray_create(); + +/** + * Destroy an omcStrArray object and release all resources associated with it. + * @param pra The pointer to the omcStrArray object to destroy. + * @return 0 on success. Otherwise -1 on error. + */ +int omcStrArray_destroy(omcStrArray* pra); + +/** + * Append a string to the string array represented by a given omcStrArray + * object. + * @param pra A pointer to an omcStrArray object to append the string to. + * @param str The string to append to the omcStrArray + * @return A pointer to the omcStrArray on success or NULL on failure + */ +omcStrArray* omcStrArray_append(omcStrArray* pra, const char* str); + +/** + * Determine the number of strings contained by a given omcStrArray object. + * @param pra A pointer to an omcStrArray object to get the number of + * strings from. + * @return The number of strings contained by the given omcStrArray object, + * or -1 on error. + */ +int omcStrArray_size(omcStrArray* pra); + +/** + * Reset/Clear a given omcStrArray object. After this call the omcStrArray + * object will not contain any strings. + * @param pra A pointer to the omcStrArray object to reset. + * @return 0 on success. Otherwise -1. + */ +int omcStrArray_reset(omcStrArray* pra); + +/** + * Set an element within an omcStrArray object to a given string. + * @param pra A pointer to the omcStrArray object to set the + * element in. + * @param str The string to set the given element to. + * @param ndx The array index of the element to set. This is zero relative, + * and must be less than the values returned by omcStrArray_size() + * @return A pointer to the omcStrArray just modified on success, or + * NULL on failure. + */ +omcStrArray* omcStrArray_set_element(omcStrArray* pra, const char* str, size_t ndx); + +/** + * Get an element within an omcStrArray object. + * @param pra A pointer to the omcStrArray object to get the string from. + * @param ndx The index of the string to retrieve within the given omcStrArray. + * @return A pointer to the string specified by ndx on success, or + * NULL on failure. + */ +const char* omcStrArray_get_element(omcStrArray* pra, size_t ndx); + #ifdef __cplusplus } #endif Modified: omccmpi/trunk/src/lib/omc/string.c =================================================================== --- omccmpi/trunk/src/lib/omc/string.c 2008-05-05 15:10:58 UTC (rev 597) +++ omccmpi/trunk/src/lib/omc/string.c 2008-05-07 20:14:16 UTC (rev 598) @@ -296,3 +296,270 @@ return dest; } +/*****************************************************************************/ +omcStrArray* +omcStrArray_create() +{ + omcStrArray* pra = (omcStrArray*)calloc(1, sizeof(omcStrArray)); + if (!pra) { + errno = ENOMEM; + return NULL; + } + pra->strs = (char**) calloc(16, sizeof(char*)); + if (!pra->strs) { + free(pra); + errno = ENOMEM; + return NULL; + } + pra->buf_size = 16; + return pra; +} + +/*****************************************************************************/ +int +omcStrArray_destroy(omcStrArray* pra) +{ + size_t nstrs; + + if (!pra) { + errno = EINVAL; + return -1; + } + + for(nstrs = 0; nstrs < pra->num_strings; nstrs++) { + if (pra->strs[nstrs]) { + free(pra->strs[nstrs]); + } + } + free(pra->strs); + free(pra); + return 0; +} + +/*****************************************************************************/ +omcStrArray* +omcStrArray_append(omcStrArray* pra, const char* str) +{ + int slen = strlen(str); + if (!pra) { + errno = EINVAL; + return NULL; + } + if (pra->num_strings == pra->buf_size-1) { + size_t nsize = pra->buf_size + 16; + char** nbuf = (char**) calloc(nsize, sizeof(char*)); + if (!nbuf) { + errno = ENOMEM; + return NULL; + } + memcpy(nbuf, pra->strs, sizeof(char*) * pra->num_strings); + free(pra->strs); + pra->strs = nbuf; + pra->buf_size = nsize; + } + pra->strs[pra->num_strings] = (char*) malloc(slen+1); + if (!pra->strs[pra->num_strings]) { + errno = ENOMEM; + return NULL; + } + strcpy(pra->strs[pra->num_strings], str); + pra->num_strings++; + return pra; +} + +/*****************************************************************************/ +int +omcStrArray_size(omcStrArray* pra) +{ + if (!pra) { + errno = EINVAL; + return -1; + } + return (int)pra->num_strings; +} + +/*****************************************************************************/ +int +omcStrArray_reset(omcStrArray* pra) +{ + size_t nstrs; + + if (!pra) { + errno = EINVAL; + return -1; + } + + for(nstrs = 0; nstrs < pra->num_strings; nstrs++) { + if (pra->strs[nstrs]) { + free(pra->strs[nstrs]); + pra->strs[nstrs] = NULL; + } + } + pra->num_strings = 0; + return 0; +} + +/*****************************************************************************/ +omcStrArray* +omcStrArray_set_element(omcStrArray* pra, const char* str, size_t ndx) +{ + int argslen = strlen(str); + + if (!pra) { + errno = EINVAL; + return NULL; + } + if (ndx >= pra->num_strings || !str) { + errno = EINVAL; + return NULL; + } + + if (argslen > strlen(pra->strs[ndx])) { + free(pra->strs[ndx]); + pra->strs[ndx] = (char*) malloc(argslen+1); + if (!pra->strs[ndx]) { + errno = ENOMEM; + return NULL; + } + } + strcpy(pra->strs[ndx], str); + return pra; +} + +/*****************************************************************************/ +const char* +omcStrArray_get_element(omcStrArray* pra, size_t ndx) +{ + if (!pra || ndx >= pra->num_strings) { + errno = EINVAL; + return NULL; + } + return pra->strs[ndx]; +} + +/*****************************************************************************/ +omcStrBuf* +omcStrBuf_create() +{ + omcStrBuf* psbuf = (omcStrBuf*) malloc(sizeof(omcStrBuf)); + if (!psbuf) { + errno = ENOMEM; + return NULL; + } + psbuf->bfr = (char*) malloc(512); + psbuf->bfr[0] = 0; + psbuf->buf_len = 512; + psbuf->str_len = 0; + return psbuf; +} + +/*****************************************************************************/ +const char* +omcStrBuf_cat(omcStrBuf* psbuf, const char* str, size_t n) +{ + size_t slen; + + if (!psbuf) { + errno = EINVAL; + return NULL; + } + + if (!str) { + return psbuf->bfr; + } + + slen = n ? n : strlen(str); + if (!slen) { + return psbuf->bfr; + } + if ((psbuf->str_len + slen) >= psbuf->buf_len) { + int nsize = psbuf->str_len + slen + 512; + char* nbuf = (char*) malloc(nsize); + if (!nbuf) { + errno = ENOMEM; + return NULL; + } + strcpy(nbuf, psbuf->bfr); + strncat(nbuf, str, slen); + free(psbuf->bfr); + psbuf->bfr = nbuf; + psbuf->buf_len = nsize; + } + else { + strncat(psbuf->bfr, str, slen); + } + psbuf->str_len = strlen(psbuf->bfr); + return psbuf->bfr; +} + +/*****************************************************************************/ +int +omcStrBuf_reset(omcStrBuf* psbuf) +{ + if (!psbuf) { + errno = EINVAL; + return -1; + } + psbuf->bfr[0] = 0; + psbuf->str_len = 0; + return 0; +} + +/*****************************************************************************/ +const char* +omcStrBuf_set(omcStrBuf* psbuf, const char* str, size_t n) +{ + size_t slen; + + if (!psbuf) { + errno = EINVAL; + return NULL; + } + + if (!str) { + omcStrBuf_reset(psbuf); + return psbuf->bfr; + } + + slen = n ? n : strlen(str); + psbuf->bfr[0] = 0; + psbuf->str_len = slen; + if (!slen) { + return psbuf->bfr; + } + + if (slen >= psbuf->buf_len) { + int nsize = psbuf->str_len + 512; + char* nbuf = (char*) malloc(nsize); + if (!nbuf) { + errno = ENOMEM; + return NULL; + } + strncpy(nbuf, str, slen); + nbuf[slen] = 0; + free(psbuf->bfr); + psbuf->bfr = nbuf; + psbuf->buf_len = nsize; + } + else { + strncpy(psbuf->bfr, str, slen); + psbuf->bfr[slen] = 0; + } + return psbuf->bfr; +} + +/*****************************************************************************/ +int +omcStrBuf_destroy(omcStrBuf* psbuf) +{ + if (!psbuf) { + errno = EINVAL; + return -1; + } + if (psbuf->bfr) { + free(psbuf->bfr); + } + free(psbuf); + return 0; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |