This PR adds everything that's needed on the segatools side to add E-Money support regarding Thinca authentication cards. I've also included set-up documentation (with a network side bonus which was as far as I could figure out so far, but I'm pretty certain no more changes to segatools will be needed) Due to the nature of a custom protcol called TCAP that Thinca uses for networking (see docs), I can't fully test that everything works as I haven't yet bothered to figure that protocol out. Tested with both APMv3 and FGO.  Reviewed-on: TeamTofuShop/segatools#35 Co-authored-by: Haruka <haruka@noreply.gitea.tendokyu.moe> Co-committed-by: Haruka <haruka@noreply.gitea.tendokyu.moe>
67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
/*
|
|
* 'slurp' reads the file identified by 'path' into a character buffer
|
|
* pointed at by 'buf', optionally adding a terminating NUL if
|
|
* 'add_nul' is true. On success, the size of the file is returned; on
|
|
* failure, -1 is returned and ERRNO is set by the underlying system
|
|
* or library call that failed.
|
|
*
|
|
* WARNING: 'slurp' malloc()s memory to '*buf' which must be freed by
|
|
* the caller.
|
|
*/
|
|
long wslurp(const wchar_t* path, char **buf, bool add_nul)
|
|
{
|
|
FILE *fp;
|
|
size_t fsz;
|
|
long off_end;
|
|
int rc;
|
|
|
|
/* Open the file */
|
|
fp = _wfopen(path, L"rb");
|
|
if( NULL == fp ) {
|
|
return -1L;
|
|
}
|
|
|
|
/* Seek to the end of the file */
|
|
rc = fseek(fp, 0L, SEEK_END);
|
|
if( 0 != rc ) {
|
|
return -1L;
|
|
}
|
|
|
|
/* Byte offset to the end of the file (size) */
|
|
if( 0 > (off_end = ftell(fp)) ) {
|
|
return -1L;
|
|
}
|
|
fsz = (size_t)off_end;
|
|
|
|
/* Allocate a buffer to hold the whole file */
|
|
*buf = malloc( fsz+(int)add_nul );
|
|
if( NULL == *buf ) {
|
|
return -1L;
|
|
}
|
|
|
|
/* Rewind file pointer to start of file */
|
|
rewind(fp);
|
|
|
|
/* Slurp file into buffer */
|
|
if( fsz != fread(*buf, 1, fsz, fp) ) {
|
|
free(*buf);
|
|
return -1L;
|
|
}
|
|
|
|
/* Close the file */
|
|
if( EOF == fclose(fp) ) {
|
|
free(*buf);
|
|
return -1L;
|
|
}
|
|
|
|
if( add_nul ) {
|
|
/* Make sure the buffer is NUL-terminated, just in case */
|
|
buf[fsz] = '\0';
|
|
}
|
|
|
|
/* Return the file size */
|
|
return (long)fsz;
|
|
} |