~ubuntu-branches/ubuntu/natty/mp3val/natty

« back to all changes in this revision

Viewing changes to crossapi.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2008-01-23 09:11:35 UTC
  • mfrom: (3.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080123091135-r10vczs51d63e8p0
Tags: 0.1.7-3
* debian/control
  - bump Standards-Version to 3.7.3
  - bump dependency against debhelper to >=5
* debian/compat
  - bump to 5
* debian/dirs
  - removed since not needed
* debian/rules
  - do not ignore anymore clean error due to missing makefile
* debian/copyright
  - clear separation of upstream author, license and copyright
  - link to /usr/share/common-licenses/GPL file
* debian/mp3val.1
  - escaped minus signs (lintian warning)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * MP3val - a program for MPEG audio file validation
3
 
 * Copyright (C) 2005-2006 Alexey Kuznetsov (ring0) and Eugen Tikhonov (jetsys)
 
3
 * Copyright (C) 2005-2007 Alexey Kuznetsov (ring0) and Eugen Tikhonov (jetsys)
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License as published by
23
23
int hFileMapping;
24
24
int iMappingLength;
25
25
 
26
 
#if (defined WIN32)||(defined __WIN32__)
 
26
#if (defined WIN32)||(defined __WIN32__)||(defined _MSC_VER)||(defined __NT__)
27
27
 
28
28
#include <windows.h>
29
29
 
79
79
        return MoveFile(szOldName,szNewName);
80
80
}
81
81
 
 
82
int CrossAPI_DeleteFile(char *szFileName) {
 
83
        return DeleteFile(szFileName);
 
84
}
 
85
 
82
86
int CrossAPI_OpenFile(char *szFileName,bool create,bool write) {
83
87
        return (int)CreateFile(szFileName,write?GENERIC_WRITE:GENERIC_READ,0,NULL,create?CREATE_ALWAYS:OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
84
88
}
94
98
}
95
99
 
96
100
int CrossAPI_CloseFile(int iHandle) {
97
 
        return CloseHandle(HANDLE(iHandle));
 
101
        return CloseHandle((HANDLE)iHandle);
98
102
}
99
103
 
100
104
int CrossAPI_GetFileSize(int iHandle) {
114
118
                return NULL;
115
119
        }
116
120
 
117
 
        hFileMapping=(int)CreateFileMapping((HANDLE)hFile,NULL,PAGE_READONLY,0,0,NULL);
 
121
        hFileMapping=(int)CreateFileMapping((HANDLE)hFile,NULL,PAGE_WRITECOPY,0,0,NULL);
 
122
        
 
123
        if(!hFileMapping) {
 
124
                CloseHandle((HANDLE)hFile);
 
125
                return NULL;
 
126
        }
118
127
 
119
 
        pImage=MapViewOfFile((HANDLE)hFileMapping,FILE_MAP_READ,0,0,0);
 
128
        pImage=MapViewOfFile((HANDLE)hFileMapping,FILE_MAP_COPY,0,0,0);
120
129
        
121
130
        iMappingLength=CrossAPI_GetFileSize(hFile);
122
131
 
131
140
        return 0;
132
141
}
133
142
 
 
143
int CrossAPI_GetFileAttr(char *filename,CROSSAPI_FILE_ATTRIBUTES *cfa) {
 
144
        HANDLE hFile;
 
145
        cfa->dwAttributes=GetFileAttributes(filename);
 
146
        hFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
 
147
        if(hFile==INVALID_HANDLE_VALUE) return -1;
 
148
        GetFileTime(hFile,&(cfa->ftCreation),&(cfa->ftLastAccess),&(cfa->ftLastWrite));
 
149
        CloseHandle(hFile);
 
150
        
 
151
        return 0;
 
152
}
 
153
 
 
154
int CrossAPI_SetFileAttr(char *filename,CROSSAPI_FILE_ATTRIBUTES *cfa,bool timestamp) {
 
155
        HANDLE hFile;
 
156
        SetFileAttributes(filename,cfa->dwAttributes);
 
157
        hFile=CreateFile(filename,FILE_WRITE_ATTRIBUTES,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
 
158
        if(hFile==INVALID_HANDLE_VALUE) return -1;
 
159
        if(timestamp) SetFileTime(hFile,&(cfa->ftCreation),&(cfa->ftLastAccess),&(cfa->ftLastWrite));
 
160
        CloseHandle(hFile);
 
161
        
 
162
        return 0;
 
163
}
 
164
 
134
165
#else
135
166
 
136
167
#include <unistd.h>
145
176
#include <stdio.h>
146
177
#include <errno.h>
147
178
#include <math.h>
 
179
#include <utime.h>
148
180
 
149
181
#define TMPBUFSIZE 8192
150
182
 
235
267
        return 1;
236
268
}
237
269
 
 
270
int CrossAPI_DeleteFile(char *szFileName) {
 
271
        int res;
 
272
        res=unlink(szFileName);
 
273
        if(!res) return 1;
 
274
        return 0;
 
275
}
 
276
 
238
277
int CrossAPI_OpenFile(char *szFileName,bool create,bool write) {
239
278
        int flags=0;
240
279
        if(create) flags|=(O_CREAT|O_TRUNC);
293
332
        dPages=iMappingLength/getpagesize();
294
333
        iRoundedMappingLength=((int)ceil(dPages)+1)*getpagesize();
295
334
 
296
 
        pImage=mmap(NULL,iRoundedMappingLength,PROT_READ,MAP_SHARED,hFile,0);
 
335
        pImage=mmap(NULL,iRoundedMappingLength,PROT_READ|PROT_WRITE,MAP_PRIVATE,hFile,0);
297
336
        
298
337
        if(pImage==MAP_FAILED) return NULL;
299
338
 
306
345
        return 0;
307
346
}
308
347
 
 
348
int CrossAPI_GetFileAttr(char *filename,CROSSAPI_FILE_ATTRIBUTES *cfa) {
 
349
        struct stat ss;
 
350
        
 
351
        stat(filename,&ss);
 
352
        
 
353
        cfa->st_mode=ss.st_mode;
 
354
        cfa->t_atime=ss.st_atime;
 
355
        cfa->t_mtime=ss.st_mtime;
 
356
        cfa->t_ctime=ss.st_ctime;
 
357
        
 
358
        return 0;
 
359
}
 
360
 
 
361
int CrossAPI_SetFileAttr(char *filename,CROSSAPI_FILE_ATTRIBUTES *cfa,bool timestamp) {
 
362
        struct utimbuf su;
 
363
        chmod(filename,cfa->st_mode);
 
364
        
 
365
        if(timestamp) {
 
366
                su.actime=cfa->t_atime;
 
367
                su.modtime=cfa->t_mtime;
 
368
                utime(filename,&su);
 
369
        }
 
370
        return 0;
 
371
}
 
372
 
309
373
#endif