diff --git a/include/share/file_utils.h b/include/share/file_utils.h new file mode 100644 index 00000000..d3aca52b --- /dev/null +++ b/include/share/file_utils.h @@ -0,0 +1,72 @@ +/* file_utils - Convenience lib for manipulating file stats + * Copyright (C) 2002 Josh Coalson + * + * 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 the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/* + * This wraps the gain_analysis lib, which is LGPL. This wrapper + * allows analysis of different input resolutions by automatically + * scaling the input signal + */ + +#ifndef FLAC__SHARE__FILE_UTILS_H +#define FLAC__SHARE__FILE_UTILS_H + +#if defined(FLAC__NO_DLL) || defined(unix) || defined(__CYGWIN__) || defined(__CYGWIN32__) +#define FILE_UTILS_API + +#else + +#ifdef FILE_UTILS_API_EXPORTS +#define FILE_UTILS_API _declspec(dllexport) +#else +#define FILE_UTILS_API _declspec(dllimport) +#define __LIBNAME__ "file_utils.lib" +#pragma comment(lib, __LIBNAME__) +#undef __LIBNAME__ + +#endif +#endif + +#include /* for off_t */ +#include /* for FILE */ +#include "FLAC/ordinals.h" + +#ifdef __cplusplus +extern "C" { +#endif + +FILE_UTILS_API void FLAC__file_utils_copy_metadata(const char *srcpath, const char *destpath); +FILE_UTILS_API off_t FLAC__file_utils_get_filesize(const char *srcpath); +FILE_UTILS_API const char *FLAC__file_utils_get_basename(const char *srcpath); + +/* read_only == false means "make file writable by user" + * read_only == true means "make file read-only for everyone" + */ +FILE_UTILS_API FLAC__bool FLAC__file_utils_change_stats(const char *filename, FLAC__bool read_only); + +/* attempts to make writable before unlinking */ +FILE_UTILS_API FLAC__bool FLAC__file_utils_remove_file(const char *filename); + +/* these will forcibly set stdin/stdout to binary mode (for OSes that require it) */ +FILE_UTILS_API FILE *FLAC__file_utils_get_binary_stdin(); +FILE_UTILS_API FILE *FLAC__file_utils_get_binary_stdout(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/share/file_utils/Makefile.am b/src/share/file_utils/Makefile.am new file mode 100644 index 00000000..d9258db0 --- /dev/null +++ b/src/share/file_utils/Makefile.am @@ -0,0 +1,20 @@ +## Process this file with automake to produce Makefile.in + +AUTOMAKE_OPTIONS = foreign + +INCLUDES = -I$(top_srcdir)/include + +noinst_LIBRARIES = libfile_utils.a + +libfile_utils_a_SOURCES = file_utils.c + +EXTRA_DIST = \ + Makefile.lite \ + Makefile.vc \ + file_utils.dsp + +debug: + $(MAKE) all CFLAGS="@DEBUG@" + +profile: + $(MAKE) all CFLAGS="@PROFILE@" diff --git a/src/share/file_utils/Makefile.lite b/src/share/file_utils/Makefile.lite new file mode 100644 index 00000000..f337baba --- /dev/null +++ b/src/share/file_utils/Makefile.lite @@ -0,0 +1,15 @@ +# +# GNU makefile +# + +topdir = ../../.. + +LIB_NAME = libfile_utils +INCLUDES = -I$(topdir)/include + +OBJS = \ + file_utils.o + +include $(topdir)/build/lib.mk + +# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/share/file_utils/Makefile.vc b/src/share/file_utils/Makefile.vc new file mode 100644 index 00000000..86e62776 --- /dev/null +++ b/src/share/file_utils/Makefile.vc @@ -0,0 +1,23 @@ +!include + +!IFDEF DEBUG +.c.obj: + $(cc) /D "_LIB" -DFLAC__NO_DLL /GX $(cdebug) $(cflags) /I "..\..\..\include" -DSTRICT -YX /Od /D "_DEBUG" $< +!else +.c.obj: + $(cc) /D "_LIB" -DFLAC__NO_DLL /O2 $(crelease) $(cflags) /I "..\..\..\include" -DSTRICT -YX -DNODEBUG $< +!endif + +C_FILES= \ + file_utils.c \ + +OBJS= $(C_FILES:.c=.obj) + +all: file_utils.lib + +file_utils.lib: $(OBJS) + link.exe -lib /nodefaultlib -out:../../../obj/lib/$*.lib $(OBJS) + +clean: + -del *.obj *.pch + -del ..\..\..\obj\lib\file_utils.lib ..\..\..\obj\lib\file_utils.pdb diff --git a/src/share/file_utils/file_utils.c b/src/share/file_utils/file_utils.c new file mode 100644 index 00000000..54054e3a --- /dev/null +++ b/src/share/file_utils/file_utils.c @@ -0,0 +1,142 @@ +/* file_utils - Convenience lib for manipulating file stats + * Copyright (C) 2002 Josh Coalson + * + * 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 the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#if defined _MSC_VER || defined __MINGW32__ +#include /* for utime() */ +#include /* for chmod(), _setmode(), unlink() */ +#include /* for _O_BINARY */ +#else +#include /* some flavors of BSD (like OS X) require this to get time_t */ +#include /* for utime() */ +#endif +#ifdef __CYGWIN__ +#include /* for setmode(), O_BINARY */ +#include /* for _O_BINARY */ +#endif +#include /* for stat(), maybe chmod() */ +#if defined _WIN32 && !defined __CYGWIN__ +#else +#include /* for unlink() */ +#endif +#include +#include +#include /* for strrchr() */ +#include "share/file_utils.h" + + +FILE_UTILS_API void FLAC__file_utils_copy_metadata(const char *srcpath, const char *destpath) +{ + struct stat srcstat; + struct utimbuf srctime; + + if(0 == stat(srcpath, &srcstat)) { + srctime.actime = srcstat.st_atime; + srctime.modtime = srcstat.st_mtime; + (void)chmod(destpath, srcstat.st_mode); + (void)utime(destpath, &srctime); + } +} + +FILE_UTILS_API off_t FLAC__file_utils_get_filesize(const char *srcpath) +{ + struct stat srcstat; + + if(0 == stat(srcpath, &srcstat)) + return srcstat.st_size; + else + return -1; +} + +FILE_UTILS_API const char *FLAC__file_utils_get_basename(const char *srcpath) +{ + const char *p; + + p = strrchr(srcpath, '/'); + if(0 == p) { + p = strrchr(srcpath, '\\'); + if(0 == p) + return srcpath; + } + return ++p; +} + +FILE_UTILS_API FLAC__bool FLAC__file_utils_change_stats(const char *filename, FLAC__bool read_only) +{ + struct stat stats; + + if(0 == stat(filename, &stats)) { +#if !defined _MSC_VER && !defined __MINGW32__ + if(read_only) { + stats.st_mode &= ~S_IWUSR; + stats.st_mode &= ~S_IWGRP; + stats.st_mode &= ~S_IWOTH; + } + else { + stats.st_mode |= S_IWUSR; + } +#else + if(read_only) + stats.st_mode &= ~S_IWRITE; + else + stats.st_mode |= S_IWRITE; +#endif + if(0 != chmod(filename, stats.st_mode)) + return false; + } + else + return false; + + return true; +} + +FILE_UTILS_API FLAC__bool FLAC__file_utils_remove_file(const char *filename) +{ + return FLAC__file_utils_change_stats(filename, /*read_only=*/false) && 0 == unlink(filename); +} + +FILE_UTILS_API FILE *FLAC__file_utils_get_binary_stdin() +{ + /* if something breaks here it is probably due to the presence or + * absence of an underscore before the identifiers 'setmode', + * 'fileno', and/or 'O_BINARY'; check your system header files. + */ +#if defined _MSC_VER || defined __MINGW32__ + _setmode(_fileno(stdin), _O_BINARY); +#elif defined __CYGWIN__ + /* almost certainly not needed for any modern Cygwin, but let's be safe... */ + setmode(_fileno(stdin), _O_BINARY); +#endif + + return stdin; +} + +FILE_UTILS_API FILE *FLAC__file_utils_get_binary_stdout() +{ + /* if something breaks here it is probably due to the presence or + * absence of an underscore before the identifiers 'setmode', + * 'fileno', and/or 'O_BINARY'; check your system header files. + */ +#if defined _MSC_VER || defined __MINGW32__ + _setmode(_fileno(stdout), _O_BINARY); +#elif defined __CYGWIN__ + /* almost certainly not needed for any modern Cygwin, but let's be safe... */ + setmode(_fileno(stdout), _O_BINARY); +#endif + + return stdout; +} diff --git a/src/share/file_utils/file_utils.dsp b/src/share/file_utils/file_utils.dsp new file mode 100644 index 00000000..fcfca0ea --- /dev/null +++ b/src/share/file_utils/file_utils.dsp @@ -0,0 +1,115 @@ +# Microsoft Developer Studio Project File - Name="file_utils" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=file_utils - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "file_utils.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "file_utils.mak" CFG="file_utils - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "file_utils - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "file_utils - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "file_utils" +# PROP Scc_LocalPath "..\..\.." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "file_utils - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\obj\lib" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I ".\include" /I "..\..\..\include" /D "NDEBUG" /D "REPLAYGAIN_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" /d "_USRDLL" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\..\obj\bin/file_utils.dll" + +!ELSEIF "$(CFG)" == "file_utils - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\obj\lib" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I ".\include" /I "..\..\..\include" /D "_DEBUG" /D "_CHATTER" /D "REPLAYGAIN_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" /d "_USRDLL" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\..\obj\bin/file_utils.dll" /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "file_utils - Win32 Release" +# Name "file_utils - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp" +# Begin Source File + +SOURCE=.\file_utils.c +# End Source File +# End Group +# Begin Group "Private Header Files" + +# PROP Default_Filter "" +# End Group +# Begin Group "Protected Header Files" + +# PROP Default_Filter "" +# End Group +# Begin Group "Public Header Files" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\include\share\file_utils.h +# End Source File +# End Group +# End Target +# End Project diff --git a/src/share/file_utils/file_utils.o b/src/share/file_utils/file_utils.o new file mode 100644 index 00000000..8578b1ed Binary files /dev/null and b/src/share/file_utils/file_utils.o differ