Open Files 5.3.0
Multi-Platform Event-Driven Application Framework
smbrm.c

This is an example of a application level file remove using the ConnectSMB Libraries

/* Copyright (c) 2021 Connected Way, LLC. All rights reserved.
* Use of this source code is unrestricted
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <unistd.h>
#include <ofc/config.h>
#include <ofc/handle.h>
#include <ofc/types.h>
#include <ofc/file.h>
#include "smbinit.h"
static OFC_DWORD rm(OFC_CTCHAR *wfilename)
{
OFC_DWORD dwLastError;
OFC_HANDLE write_file;
OFC_BOOL ret;
dwLastError = OFC_ERROR_SUCCESS;
write_file = OFC_HANDLE_NULL;
/*
* Open up our write file. If it exists, it will be deleted
*/
write_file = OfcCreateFile(wfilename,
0,
if (write_file == OFC_INVALID_HANDLE_VALUE)
{
dwLastError = OfcGetLastError();
}
else
{
OfcCloseHandle(write_file);
}
return (dwLastError);
}
int main (int argc, char **argp)
{
OFC_TCHAR *wfilename;
OFC_DWORD ret;
size_t len;
mbstate_t ps;
const char *cursor;
smbcp_init();
if (argc < 2)
{
printf ("Usage: smbrm <destination>\n");
exit (1);
}
memset(&ps, 0, sizeof(ps));
len = strlen(argp[1]) + 1;
wfilename = malloc(sizeof(wchar_t) * len);
cursor = argp[1];
mbsrtowcs(wfilename, &cursor, len, &ps);
printf("Removing %s: ", argp[1]);
fflush(stdout);
ret = rm(wfilename);
free(wfilename);
int status;
if (ret == OFC_ERROR_SUCCESS)
{
printf("[ok]\n");
status = 0;
}
else
{
printf("[failed]\n");
printf("%s\n", ofc_get_error_string(ret));
status = 1;
}
/*
* Deactivate the openfiles stack
*/
printf("Deactivating Stack\n");
smbcp_deactivate();
exit(status);
}
@ OFC_ERROR_SUCCESS
Definition: file.h:1508
OFC_CORE_LIB OFC_BOOL OfcCloseHandle(OFC_HANDLE hObject)
OFC_CORE_LIB const OFC_CHAR * ofc_get_error_string(OFC_DWORD dwerr)
OFC_CORE_LIB OFC_DWORD OfcGetLastError(OFC_VOID)
#define OfcCreateFile
Definition: file.h:2623
@ OFC_OPEN_EXISTING
Definition: file.h:258
@ OFC_FILE_ATTRIBUTE_NORMAL
Definition: file.h:298
@ OFC_FILE_FLAG_DELETE_ON_CLOSE
Definition: file.h:364
@ OFC_GENERIC_WRITE
Definition: file.h:211
@ OFC_FILE_DELETE
Definition: file.h:194
#define OFC_HANDLE_NULL
Definition: handle.h:64
OFC_DWORD_PTR OFC_HANDLE
Definition: handle.h:43
#define OFC_INVALID_HANDLE_VALUE
Definition: handle.h:52
OFC_UINT8 OFC_BOOL
Definition: types.h:624
OFC_UINT32 OFC_DWORD
Definition: types.h:430
OFC_WCHAR OFC_TCHAR
Definition: types.h:463
#define OFC_NULL
Definition: types.h:656
const OFC_WCHAR OFC_CTCHAR
Definition: types.h:467