source: trunk/dll/subj.c@ 1039

Last change on this file since 1039 was 1039, checked in by Gregg Young, 17 years ago

Removed unnecessary xfrees and included fortify.h where needed; moved several misplaced (x)frees;

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1
2/***********************************************************************
3
4 $Id: subj.c 1039 2008-07-05 22:16:21Z gyoung $
5
6 Edit .subject EAs
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2006 Steven H.Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 17 Jul 06 SHL Use Runtime_Error
13 06 Aug 07 GKY Increase Subject EA to 1024
14 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
15 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
16 29 Feb 08 GKY Use xfree where appropriate
17
18***********************************************************************/
19
20#include <stdlib.h>
21#include <string.h>
22#include <ctype.h>
23
24#define INCL_WIN
25#define INCL_DOS
26#define INCL_DOSERRORS
27#define INCL_LONGLONG
28
29#include "fm3dlg.h"
30#include "fm3str.h"
31#include "errutil.h" // Dos_Error...
32#include "strutil.h" // GetPString
33#include "fm3dll.h"
34#include "fortify.h"
35
36static PSZ pszSrcFile = __FILE__;
37
38INT Subject(HWND hwnd, CHAR * filename)
39{
40 APIRET rc;
41 EAOP2 eaop;
42 PGEA2LIST pgealist;
43 PFEA2LIST pfealist;
44 PGEA2 pgea;
45 PFEA2 pfea;
46 CHAR *value, subject[1024], oldsubject[1024];
47 STRINGINPARMS sip;
48 INT ret = 0;
49
50 *subject = 0;
51 pgealist = xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__);
52 if (pgealist) {
53 pgea = &pgealist->list[0];
54 strcpy(pgea->szName, SUBJECT);
55 pgea->cbName = strlen(pgea->szName);
56 pgea->oNextEntryOffset = 0;
57 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
58 pfealist = xmallocz(1024, pszSrcFile, __LINE__);
59 if (pfealist)
60 free(pgealist);
61 else {
62 pfealist->cbList = 1024;
63 eaop.fpGEA2List = pgealist;
64 eaop.fpFEA2List = pfealist;
65 eaop.oError = 0;
66 rc = DosQueryPathInfo(filename, FIL_QUERYEASFROMLIST,
67 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
68 free(pgealist);
69 if (!rc) {
70 pfea = &eaop.fpFEA2List->list[0];
71 value = pfea->szName + pfea->cbName + 1;
72 value[pfea->cbValue] = 0;
73 if (*(USHORT *) value == EAT_ASCII)
74 strncpy(subject, value + (sizeof(USHORT) * 2), 1023);
75 subject[1023] = 0;
76 }
77 free(pfealist);
78 if (rc == ERROR_SHARING_VIOLATION || rc == ERROR_ACCESS_DENIED) {
79 saymsg(MB_CANCEL,
80 hwnd,
81 GetPString(IDS_OOPSTEXT),
82 GetPString(IDS_EASBUSYTEXT), filename);
83 return 2; // Error
84 }
85 else if (rc) {
86 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
87 "DosQueryPathInfo");
88 return 2; // Error
89 }
90 }
91 }
92 memset(&sip, 0, sizeof(sip));
93 strcpy(oldsubject, subject);
94 sip.help = GetPString(IDS_SUBJECTINPUTHELPTEXT);
95 sip.ret = subject;
96 sip.prompt = GetPString(IDS_SUBJECTINPUTPROMPTTEXT);
97 sip.inputlen = 1024;
98 sip.title = filename;
99 if (WinDlgBox
100 (HWND_DESKTOP, hwnd, InputDlgProc, FM3ModHandle, STR_FRAME, &sip)
101 && isalpha(*filename)
102 && !(driveflags[toupper(*filename) - 'A'] & DRIVE_NOTWRITEABLE)) {
103 subject[1023] = 0;
104 bstrip(subject);
105 if (strcmp(oldsubject, subject)) {
106
107 ULONG ealen;
108 USHORT len;
109 CHAR *eaval;
110
111 len = strlen(subject);
112 if (len)
113 ealen = sizeof(FEA2LIST) + 9 + len + 4;
114 else
115 ealen = sizeof(FEALIST) + 9;
116 rc = DosAllocMem((PPVOID) & pfealist, ealen + 1L,
117 OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE);
118 if (rc)
119 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
120 GetPString(IDS_OUTOFMEMORY));
121 else {
122 memset(pfealist, 0, ealen + 1);
123 pfealist->cbList = ealen;
124 pfealist->list[0].oNextEntryOffset = 0L;
125 pfealist->list[0].fEA = 0;
126 pfealist->list[0].cbName = 8;
127 strcpy(pfealist->list[0].szName, SUBJECT);
128 if (len) {
129 eaval = pfealist->list[0].szName + 9;
130 *(USHORT *) eaval = (USHORT) EAT_ASCII;
131 eaval += sizeof(USHORT);
132 *(USHORT *) eaval = (USHORT) len;
133 eaval += sizeof(USHORT);
134 memcpy(eaval, subject, len);
135 pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
136 }
137 else
138 pfealist->list[0].cbValue = 0;
139 eaop.fpGEA2List = (PGEA2LIST) 0;
140 eaop.fpFEA2List = pfealist;
141 eaop.oError = 0;
142 rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
143 &eaop, sizeof(eaop), DSPI_WRTTHRU);
144 DosFreeMem(pfealist);
145 if (rc) {
146 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
147 GetPString(IDS_ERRORSETTINGSUBJECTTEXT), filename);
148 }
149 else
150 ret = 1; // OK
151 }
152 }
153 }
154 return ret; // No change?
155}
156
157#pragma alloc_text(FMINPUT,Subject)
Note: See TracBrowser for help on using the repository browser.