Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #include <sys/types.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23.  
  24. #include "desktop/cookies.h"
  25. #include "utils/log.h"
  26. #include "utils/messages.h"
  27. #include "utils/utils.h"
  28. #include "utils/url.h"
  29.  
  30. void warn_user(const char *warning, const char *detail)
  31. {
  32.         LOG(("%s %s", warning, detail));
  33. }
  34.  
  35. void die(const char *error)
  36. {
  37.         LOG(("%s", error));
  38.         exit(1);
  39. }
  40.  
  41. /**
  42.  * Return the filename part of a full path
  43.  *
  44.  * \param path full path and filename
  45.  * \return filename (will be freed with free())
  46.  */
  47. char *filename_from_path(char *path)
  48. {
  49.         char *leafname;
  50.  
  51.         leafname = strrchr(path, '/');
  52.         if (!leafname)
  53.                 leafname = path;
  54.         else
  55.                 leafname += 1;
  56.  
  57.         return strdup(leafname);
  58. }
  59.  
  60. /**
  61.  * Add a path component/filename to an existing path
  62.  *
  63.  * \param path buffer containing path + free space
  64.  * \param length length of buffer "path"
  65.  * \param newpart string containing path component to add to path
  66.  * \return true on success
  67.  */
  68.  
  69. bool path_add_part(char *path, int length, const char *newpart)
  70. {
  71.         if(path[strlen(path) - 1] != '/')
  72.                 strncat(path, "/", length);
  73.  
  74.         strncat(path, newpart, length);
  75.  
  76.         return true;
  77. }
  78.