473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Linux equivalent

180 100+
Hi guys,
What are the changes to be made to make this code run on linux.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main ()
  5. {
  6.   FILE *inFile, *outFile;
  7.   char * buffer;
  8.   size_t inResult;
  9.   size_t outResult;
  10.  
  11.   char tempFilePath[L_tmpnam_s];
  12.   errno_t err;
  13.  
  14.   tmpfile_s(&outFile);
  15.  
  16.   if( outFile )
  17.   {      
  18.       err = tmpnam_s( tempFilePath, L_tmpnam_s );
  19.       if (err)
  20.       {
  21.          printf("Error occurred creating unique filename.\n");
  22.          exit(1);
  23.       }
  24.       else
  25.       {
  26.          printf( "%s is safe to use as a temporary file.\n", tempFilePath );
  27.       }
  28.  
  29.  
  30.       fopen_s(&inFile, "test.txt", "rb");
  31.       if( !inFile )
  32.         {
  33.         printf("Error Opening inFile\n");
  34.         return 0;
  35.         }
  36.  
  37.       // obtain file size:
  38.       fseek (inFile , 0 , SEEK_END);
  39.       long lSize = ftell (inFile);
  40.       rewind (inFile);
  41.       buffer = (char*) malloc (sizeof(char)*lSize);
  42.       if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
  43.  
  44.       inResult = fread (buffer, 1, lSize, inFile);
  45.       if (inResult != lSize)
  46.       {
  47.           fputs ("Reading error",stderr); 
  48.           exit (3);
  49.       }    
  50.  
  51.       outResult = fwrite( buffer, 1, inResult, outFile );
  52.       if (outResult != inResult)
  53.       {
  54.           fputs ("Reading error",stderr); 
  55.           exit (3);
  56.       }    
  57.  
  58.   }
  59.   free(buffer);
  60.   fclose (inFile);
  61.   fclose (outFile);    
  62.   return 0;
  63. }
Mar 1 '07 #1
6 4934
horace1
1,510 Expert 1GB
so long as you use standard libraries (which you do) and are careful about operating system specific filename naming conventions you should be OK.
However, the code as posted won't compile, e.g. L_tmpnam_s, errno_t and lSize' are undeclared identifiers.
Mar 1 '07 #2
vermarajeev
180 100+
so long as you use standard libraries (which you do) and are careful about operating system specific filename naming conventions you should be OK.
However, the code as posted won't compile, e.g. L_tmpnam_s, errno_t and lSize' are undeclared identifiers.
I know about that error and tried on my system too and get the same error. I think I was not clear. The above code runs well on windows system but on linux it gives me errors. But I somehow fixed the problem.

Now my another question is
I have two files 'file1.txt' file2.enc'.

'file1.txt' contains plain data and 'file2.enc' contains encoded data.

Presently I'm deleting 'file1.txt' and retaining back 'file2.enc'.

What I want is, use 'file1.txt' to both encode and decode?

I have a solution for this
Solution-->
Let two files 'file1.txt' and 'file2.enc' be created. Delete 'file.txt' and then rename 'file2.enc' to 'file1.txt.'
But the question is since I'm deleting and renaming the files. Will it not make my application too slow????? I think renaming and deleting the files is at operating system level, so it might result in performace problems.

Can you provide me a better idea to do the same. My code should be portable on both windows and linux.

Thanks in advance
Mar 2 '07 #3
horace1
1,510 Expert 1GB
I have not found using remove() and rename() causing any significant delay
Mar 2 '07 #4
DeMan
1,806 1GB
it won't make the process too slow but (and I assume this is kinda where your questions leading).....
if you encode file1.txt in file2.enc.....
then delete file1.txt (which is a good idea, why keep the plaintext, we encrypted for a reason).....
then rename file2.enc to be file1.txt....
then your encoded file will be called file1.txt.....
but I think you are more concerned with OVERWRITING the data that previously was file1.txt???
renaming the encoded file to the plaintext file does not do this - is this what you want to do?
Mar 2 '07 #5
vermarajeev
180 100+
it won't make the process too slow but (and I assume this is kinda where your questions leading).....
if you encode file1.txt in file2.enc.....
then delete file1.txt (which is a good idea, why keep the plaintext, we encrypted for a reason).....
then rename file2.enc to be file1.txt....
then your encoded file will be called file1.txt.....
but I think you are more concerned with OVERWRITING the data that previously was file1.txt???
renaming the encoded file to the plaintext file does not do this - is this what you want to do?
Yes my encoded file will be called file1.txt. No I'm not all bothered about overwriting the data.

The user gives me a plain text file. I encode the data then the same file should have the encoded data. That is my target.

One more doubt-->
When I delete a file using ::remove( fileName ) Will the file get deleted from hard drive or will it be on memory??? Is there any way for the hacker to get the deleted file??? If yes what should I do to not allow the hacker to hack my file...

Waiting eagerly....
Mar 2 '07 #6
DeMan
1,806 1GB
Hi Again,

Overwriting the information is one way to make it a little harder for hackers BUT
These days, people have devised mehtods to find even overwritten data. Some companies (depending on the sensitivity of their data) overwrite eleven (some probably more, but I don't know) times with random bitstrings....(the less pattern there is, the more difficult it is for someone to tell at which layer that bit was a given value).

Depending on what you are using the information for (and more importantly where), it may be sufficient to simply rwemove the file as you do....
If you are encrypting military secrets you would want to overwrite no matter what. If you are encrypting account information for a bank (especially where several people have access to the computer/network you ar e using) you probably want to overwrite. If you are encrypting a telephone/Addressbook on a home computer that is only used by your family, I wouldn't bother overwriting (unless you have hackers in the family).....

Hope I haven't confused you further
Mar 2 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Ranger West | last post by:
Hello there, Are there any out-of-the box handhelds that run Linux/Apache/MYSQL and PHP? Does Redhat, Suse, or Gentoo support any handhelds? I know the Zaurus comes close, but I've heard...
14
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server...
1
by: harshaL | last post by:
Guys, Actually i want to implement Doors on Linux using C++ coding, on threads, thing is following Interfaces door_bind, door_call, door_create, door_cred, door_info, door_return,...
5
by: aman | last post by:
I need to implement getche() but as I am working on Linux and that I cant use conio.h, is there any equivalent???
3
by: Bruno LIVERNAIS | last post by:
Hi, We are currently installing a DB2 V9 ESE on a Linux server (RHEL4U4-x86_64). Installation runs successfully on each node. Database user environment is OK and the instance is well created. To...
15
by: Konstantin Andreev | last post by:
I'm almost sure I've found bad bug, but for a while I can't neither confirm nor reject this. If anybody could make an independent test on it's own system, I'd appreciate it very much. The...
1
by: neelz | last post by:
Hi Friends, I am porting an application from Linux to Windows. In the source code, <sys/times.h>, time.h etc. header files are included and tms structure, times() function are getting used. I have...
9
by: Aditi | last post by:
I am working around a problem called Y2038 bug....
0
by: c0d3lib | last post by:
I am attempting to implement, what I believe to be, an unusual scenario, and am hoping to find someone that has experience with something similar. I currently have a series of physical and logical...
0
by: tvnaidu | last post by:
I am looking for windows SetTimer equivalent routine in Linux, need to port this line to Linux from Windows. watchdog_timer_id=SetTimer(NULL, 0, 60000, (TIMERPROC)TimerProc);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.