/**
 * SACD Ripper - https://github.com/sacd-ripper/
 *
 * Copyright (c) 2010-2015 by respective authors.
 *
 * 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
 *
 */

#ifndef __FILEUTILS_H__
#define __FILEUTILS_H__

#include <stdio.h>

#if defined(_WIN32) && !defined(__MINGW32__)
typedef int mode_t;
#else
#include <sys/stat.h>
#endif

// substitute various items into a formatted string (similar to printf)
//
// format - the format of the filename
// tracknum - gets substituted for %N in format
// year - gets substituted for %Y in format
// artist - gets substituted for %A in format
// album - gets substituted for %L in format
// title - gets substituted for %T in format
//
// NOTE: caller must free the returned string!
char * parse_format(const char * format, int tracknum, const char * year, const char * artist, const char * album, const char * title);

// construct a filename from various parts
//
// path - the path the file is placed in (don't include a trailing '/')
// dir - the parent directory of the file (don't include a trailing '/')
// file - the filename
// extension - the suffix of a file (don't include a leading '.')
//
// NOTE: caller must free the returned string!
// NOTE: any of the parameters may be NULL to be omitted
char * make_filename(const char * path, const char * dir, const char * file, const char * extension);

int recursive_mkdir(char *pathAndName, char *base_dir, mode_t mode);

int recursive_parent_mkdir(char* pathAndName, mode_t mode);

void sanitize_filename(char *f);

void sanitize_filepath(char *f);

char *get_unique_filename(char *dev, char *dir, char *file, char *ext);

char * get_unique_path(char *dir, char *file, const char *ext);

char * get_unique_dir(char *device, char *dir);
int stat_wrap(const char *pathname, struct stat *buf);
int path_dir_exists(char *path);

#endif
