syncfiles/macos/tempfile.c
Dietrich Epp 4d4ee214b3 Create classic Mac OS GUI program
The GUI program's project is not checked in. It was compiled and tested
with CodeWarrior Pro 4.

The GUI program allows users to create new synchronization projects,
select folders to synchronize, and save and open projects. The code is
probably broken and buggy, and probably dereferences NULL pointers here
and there, but the basic shell is there.
2022-04-10 04:09:17 -04:00

51 lines
1.1 KiB
C

#include "tempfile.h"
#include <string.h>
// Filename prefix for temporary files.
static const char kTempPrefix[] = "SyncFiles.";
// Hexadecimal digits.
static const char kHexDigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
static void U32ToHex(unsigned char *ptr, UInt32 x)
{
int i;
for (i = 0; i < 8; i++) {
ptr[7 - i] = kHexDigits[x & 15];
x >>= 4;
}
}
OSErr MakeTempFile(short vRefNum, FSSpec *spec)
{
short tempVRefNum;
long tempParID;
unsigned long time;
OSErr err;
int pos;
unsigned char name[32];
// This is inspired by IM: Files listing 1-10, page 1-25.
// Generate hopefully unique name.
GetDateTime(&time);
memcpy(name + 1, kTempPrefix, sizeof(kTempPrefix) - 1);
pos = sizeof(kTempPrefix);
U32ToHex(name + pos, time);
pos += 8;
name[0] = pos - 1;
err = FindFolder(vRefNum, kTemporaryFolderType, TRUE, &tempVRefNum,
&tempParID);
if (err != noErr) {
return err;
}
err = FSMakeFSSpec(tempVRefNum, tempParID, name, spec);
if (err != noErr && err != fnfErr) {
return err;
}
return noErr;
}