cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/src/protocol/delfile.c

58 lines
1.8 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* protocol/delfile.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**
* p7_delfile:
* Deletes a distant file.
*
* @arg handle the libp7 handle
* @arg dirname the directory name
* @arg filename the file name
* @arg devname the device name
* @return if it worked
*/
int p7_delfile(p7_handle_t *handle,
const char *dirname, const char *filename, const char *devname)
{
int err;
/* make checks */
chk_filename(filename);
chk_dirname(dirname);
chk_handle(handle);
chk_active(handle);
/* send command packet */
log_info("sending command");
if ((err = p7_send_cmdfls_delfile(handle,
dirname, filename, devname))) {
log_fatal("couldn't send command/get its response");
return (err);
} else if (response.type != p7_pt_ack && response.type != p7_pt_error) {
log_fatal("received an invalid answer");
return (p7_error_unknown);
}
/* - check error - */
if (response.type == p7_pt_error) switch (response.error.code) {
case p7_ec_overwrite_impossible:
log_fatal("file not found");
return (p7_error_notfound);
default:
log_fatal("unknown error");
return (p7_error_unknown);
}
/* we're done */
return (0);
}