From 42f9667a2b7d0b32f4aa3d6912defbfa15e0aec5 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Fri, 8 Aug 1997 23:28:11 +0000 Subject: Initial checkin. --- libftpconn/fname.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 libftpconn/fname.c (limited to 'libftpconn') diff --git a/libftpconn/fname.c b/libftpconn/fname.c new file mode 100644 index 00000000..7f5959d3 --- /dev/null +++ b/libftpconn/fname.c @@ -0,0 +1,71 @@ +/* Filename frobbing + + Copyright (C) 1997 Free Software Foundation, Inc. + Written by Miles Bader + This file is part of the GNU Hurd. + + The GNU Hurd 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, or (at + your option) any later version. + + The GNU Hurd 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, USA. */ + +#include + +#include "ftpconn.h" + +/* Give a name which refers to a directory file, and a name in that + directory, this should return in COMPOSITE the composite name refering to + that name in that directory, in malloced storage. */ +error_t +ftp_conn_append_name (struct ftp_conn *conn, + const char *dir, const char *name, + char **composite) +{ + if (conn->syshooks.append_name) + return (*conn->syshooks.append_name) (conn, dir, name, composite); + else + return EOPNOTSUPP; +} + +/* If the name of a file COMPOSITE is a composite name (containing both a + filename and a directory name), this function will return the name + component only in BASE, in malloced storage, otherwise it simply returns a + newly malloced copy of COMPOSITE in BASE. */ +error_t +ftp_conn_basename (struct ftp_conn *conn, const char *composite, char **base) +{ + if (conn->syshooks.basename) + { + error_t err; + size_t in_size = strlen (composite) + 1; + char *in = strdup (composite), *out = in; + + if (! in) + return ENOMEM; + + err = (*conn->syshooks.basename) (conn, &out); + if (err || out != in) + { + if (!err && out >= in && out < in + in_size) + /* OUT uses storage from IN, but not at the beginning. */ + out = strdup (out); + free (in); + } + + if (! err) + *base = out; + + return err; + } + else + return EOPNOTSUPP; +} -- cgit v1.2.3