DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
#include
#include
#include
#include
#include "NXU_File.h" #include "NXU_string.h" #ifdef _MSC_VER #pragma warning(disable:4996) // Disabling stupid .NET deprecated warning. #endif namespace NXU { #define DEFAULT_BUFFER_SIZE 1000000 #define DEFAULT_GROW_SIZE 2000000 #if defined(LINUX) # define _stricmp(a,b) strcasecmp((a),(b)) #endif class NXU_FILE { public: NXU_FILE(const char *fname,const char *spec,void *mem,int len) { mMyAlloc = false; mRead = true; // default is read access. mFph = 0; mData = (char *) mem; mLen = len; mLoc = 0; if ( spec && _stricmp(spec,"wmem") == 0 ) { mRead = false; if ( mem == 0 || len == 0 ) { mData = new char[DEFAULT_BUFFER_SIZE]; mLen = DEFAULT_BUFFER_SIZE; mMyAlloc = true; } } if ( mData == 0 ) { mFph = fopen(fname,spec); } strncpy(mName,fname,512); } ~NXU_FILE(void) { if ( mMyAlloc ) { delete mData; } if ( mFph ) { fclose(mFph); } } int read(char *data,int size) { int ret = 0; if ( (mLoc+size) <= mLen ) { memcpy(data, &mData[mLoc], size ); mLoc+=size; ret = 1; } return ret; } int write(const char *data,int size) { int ret = 0; if ( (mLoc+size) >= mLen && mMyAlloc ) // grow it { int newLen = mLen+DEFAULT_GROW_SIZE; if ( size > newLen ) newLen = size+DEFAULT_GROW_SIZE; char *data = new char[newLen]; memcpy(data,mData,mLoc); delete mData; mData = data; mLen = newLen; } if ( (mLoc+size) <= mLen ) { memcpy(&mData[mLoc],data,size); mLoc+=size; ret = 1; } return ret; } int read(void *buffer,int size,int count) { int ret = 0; if ( mFph ) { ret = (int) fread(buffer,size,count,mFph); } else { char *data = (char *)buffer; for (int i=0; i
= mLen ) ret = 1; } return ret; } int error(void) { int ret = 0; if ( mFph ) { ret = ferror(mFph); } return ret; } FILE *mFph; char *mData; int mLen; int mLoc; bool mRead; char mName[512]; bool mMyAlloc; }; NXU_FILE * nxu_fopen(const char *fname,const char *spec,void *mem,int len) { NXU_FILE *ret = 0; ret = new NXU_FILE(fname,spec,mem,len); if ( mem == 0 && ret->mData == 0) { if ( ret->mFph == 0 ) { delete ret; ret = 0; } } return ret; } void nxu_fclose(NXU_FILE *file) { delete file; } int nxu_fread(void *buffer,int size,int count,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->read(buffer,size,count); } return ret; } int nxu_fwrite(const void *buffer,int size,int count,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->write(buffer,size,count); } return ret; } int nxu_fprintf(NXU_FILE *fph,const char *fmt,...) { int ret = 0; char buffer[2048]; va_list ap; va_start(ap, fmt); vsprintf(buffer, fmt, ap); va_end(ap); if ( fph ) { ret = fph->writeString(buffer); } return ret; } int nxu_fflush(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->flush(); } return ret; } int nxu_fseek(NXU_FILE *fph,int loc,int mode) { int ret = 0; if ( fph ) { ret = fph->seek(loc,mode); } return ret; } int nxu_ftell(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->tell(); } return ret; } int nxu_fputc(char c,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->myputc(c); } return ret; } int nxu_fputs(const char *str,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->writeString(str); } return ret; } int nxu_feof(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->eof(); } return ret; } int nxu_ferror(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->error(); } return ret; } void * nxu_getMemBuffer(NXU_FILE *fph,int &outputLength) { outputLength = 0; void * ret = 0; if ( fph ) { ret = fph->mData; outputLength = fph->mLoc; fph->mMyAlloc = false; } return ret; } }; // end of NXU namespace
NXU_File.cpp
Page URL
File URL
Prev
6/21
Next
Download
( 5 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.