Fix `puttygen-unix-perms': f_open(), PuTTY's wrapper on fopen, now
[u/mdw/putty] / mac / macmisc.c
index a5cb1f5..ce32eb4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macmisc.c,v 1.1 2003/02/12 23:53:15 ben Exp $ */
+/* $Id$ */
 /*
  * Copyright (c) 1999, 2003 Ben Harris
  * All rights reserved.
@@ -28,6 +28,8 @@
 #include <MacTypes.h>
 #include <Dialogs.h>
 #include <Files.h>
+#include <MacWindows.h>
+#include <Processes.h>
 #include <Quickdraw.h>
 #include <TextUtils.h>
 
@@ -35,6 +37,8 @@
 #include <stdio.h>
 
 #include "putty.h"
+#include "mac.h"
+#include "ssh.h"
 
 #if TARGET_API_MAC_CARBON
 /*
@@ -48,6 +52,22 @@ const CFAllocatorRef kCFAllocatorDefault = NULL;
 QDGlobals qd;
 #endif
 
+/*
+ * Like FrontWindow(), but return NULL if we aren't the front process
+ * (i.e. the front window isn't one of ours).
+ */
+WindowPtr mac_frontwindow(void)
+{
+    ProcessSerialNumber frontpsn;
+    ProcessSerialNumber curpsn = { 0, kCurrentProcess };
+    Boolean result;
+
+    GetFrontProcess(&frontpsn);
+    if (SameProcess(&frontpsn, &curpsn, &result) == noErr && result)
+       return FrontWindow();
+    return NULL;
+}
+
 void fatalbox(char *fmt, ...) {
     va_list ap;
     Str255 stuff;
@@ -100,7 +120,7 @@ const char *filename_to_str(const Filename *fn)
     char *newpath;
 
     if (path != NULL) sfree(path);
-    path = smalloc(fn->fss.name[0]);
+    path = snewn(fn->fss.name[0], char);
     p2cstrcpy(path, fn->fss.name);
     pb.dirInfo.ioNamePtr = dirname;
     pb.dirInfo.ioVRefNum = fn->fss.vRefNum;
@@ -111,7 +131,7 @@ const char *filename_to_str(const Filename *fn)
        err = PBGetCatInfoSync(&pb);
 
        /* XXX Assume not A/UX */
-       newpath = smalloc(strlen(path) + dirname[0] + 2);
+       newpath = snewn(strlen(path) + dirname[0] + 2, char);
        p2cstrcpy(newpath, dirname);
        strcat(newpath, ":");
        strcat(newpath, path);
@@ -136,7 +156,7 @@ int filename_is_null(Filename fn)
     return fn.fss.vRefNum == 0 && fn.fss.parID == 0 && fn.fss.name[0] == 0;
 }
 
-FILE *f_open(Filename fn, char const *mode)
+FILE *f_open(Filename fn, char const *mode, int is_private)
 {
     short savevol;
     long savedir;
@@ -153,6 +173,33 @@ FILE *f_open(Filename fn, char const *mode)
     return ret;
 }
 
+struct tm ltime(void)
+{
+    struct tm tm;
+    DateTimeRec d;
+    GetTime(&d);
+
+    tm.tm_sec=d.second;
+    tm.tm_min=d.minute;
+    tm.tm_hour=d.hour;
+    tm.tm_mday=d.day;
+    tm.tm_mon=d.month-1;
+    tm.tm_year=d.year-1900;
+    tm.tm_wday=d.dayOfWeek;
+    tm.tm_yday=1; /* GetTime doesn't tell us */
+    tm.tm_isdst=0; /* Have to do DST ourselves */
+
+    /* XXX find out DST adjustment and add it */
+
+    return tm;
+}
+
+const char platform_x11_best_transport[] = "localhost";
+
+char *platform_get_x_display(void) {
+    return NULL;
+}
+
 /*
  * Local Variables:
  * c-file-style: "simon"