This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[patch/rebase] Fix build problems in imagehelper
- From: Corinna Vinschen <corinna-cygwin at cygwin dot com>
- To: cygwin-apps at cygwin dot com
- Date: Mon, 20 Jun 2011 17:25:59 +0200
- Subject: [patch/rebase] Fix build problems in imagehelper
- Reply-to: cygwin-apps at cygwin dot com
Hi Jason,
here's the first of my patches to rebase.
When building with g++-4, you get a bunch of warnings. Most of them are
due to "char *" vs. "const char *" type conversions, but one of them is
due to the usage of the old, deprecated function cygwin_conv_to_win32_path.
I replaced that with a call to cygwin_conv_path and allowed for the path
to be up to PATH_MAX (4K) long, rather than just MAX_PATH (260) by
calling CreateFileW instead of CreateFileA.
Ok to apply?
Thanks,
Corinna
* imagehelper: Throughout, replace char * with const char *
where appropriate.
* imagehelper/Makefile.in: Use $(AR) instead of ar to allow easier
cross-compiling.
* imagehelper/objectfile.cc (Win32Path): Return PCWSTR rather than
char *. Convert buf to static WCHAR buffer of size PATH_MAX.
On Cygwin call cygwin_conv_path rather than cygwin_conv_to_win32_path.
Return pointer to buf.
(ObjectFile::ObjectFile): Call CreateFileW.
Index: imagehelper/Makefile.in
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/Makefile.in,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Makefile.in
--- imagehelper/Makefile.in 20 Jun 2011 14:22:01 -0000 1.1.1.1
+++ imagehelper/Makefile.in 20 Jun 2011 15:21:16 -0000
@@ -34,7 +34,7 @@ all: $(LIB_TARGET) $(TARGETS)
$(LIB_TARGET): $(LIB_TARGET_FILE)
$(LIB_TARGET_FILE): $(LIB_FILES)
- ar -cru $@ $^
+ $(AR) -cru $@ $^
$(REBASE_TARGET): $(REBASE_FILES)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
Index: imagehelper/objectfile.cc
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/objectfile.cc,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 objectfile.cc
--- imagehelper/objectfile.cc 20 Jun 2011 14:22:01 -0000 1.1.1.1
+++ imagehelper/objectfile.cc 20 Jun 2011 15:21:16 -0000
@@ -29,21 +29,23 @@
#ifdef __CYGWIN__
#include <sys/cygwin.h>
+#else
+#define PATH_MAX MAX_PATH
#endif
-#ifdef __CYGWIN__
-
-static char * Win32Path(char * s)
+static PCWSTR Win32Path(char * s)
{
- char buf[MAX_PATH];
+ /* No multi-threading so a static buffer is sufficient for this call. */
+ static WCHAR buf[PATH_MAX];
if (!s || *s == '\0')
- return "";
- cygwin_conv_to_win32_path(s, buf);
- return strdup(buf);
-}
+ return L"";
+#ifdef __CYGWIN__
+ cygwin_conv_path(CCP_POSIX_TO_WIN_W, s, buf, PATH_MAX * sizeof (WCHAR));
#else
-#define Win32Path(s) s
+ MultiByteToWideChar (CP_OEM, 0, s, -1, buf, PATH_MAX);
#endif
+ return buf;
+}
//------- class ObjectFile ------------------------------------------
@@ -58,7 +60,7 @@ ObjectFile::ObjectFile(char *aFileName,
hfilemapping = 0;
// search for raw filename
- hfile = CreateFile(Win32Path(aFileName), writeable ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
+ hfile = CreateFileW(Win32Path(aFileName), writeable ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
if (hfile != INVALID_HANDLE_VALUE)
FileName = strdup(aFileName);
@@ -80,7 +82,7 @@ ObjectFile::ObjectFile(char *aFileName,
strcat(name,basename);
if (debug)
std::cerr << __FUNCTION__ << ": name:" << name << std::endl;
- hfile = CreateFile(Win32Path(name), writeable ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
+ hfile = CreateFileW(Win32Path(name), writeable ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
// found
if (hfile != INVALID_HANDLE_VALUE)
break;
@@ -318,7 +320,7 @@ bool LinkedObjectFile::PrintDependencies
imports->reset();
- char *filler=" ";
+ const char *filler=" ";
if (!isPrinted)
{
Index: imagehelper/sections.cc
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/sections.cc,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 sections.cc
--- imagehelper/sections.cc 20 Jun 2011 14:22:01 -0000 1.1.1.1
+++ imagehelper/sections.cc 20 Jun 2011 15:21:16 -0000
@@ -37,7 +37,7 @@ Section::Section(void *aFileBase, Sectio
// FIXME: should be print() with returning ostream, but this isn't supported with gcc 2.
-void Section::debugprint(char *title)
+void Section::debugprint(const char *title)
{
std::cerr << std::setw(10) << std::setfill(' ') << title \
<< " name: " << std::setw(8) << std::setfill(' ') << Name \
@@ -47,7 +47,7 @@ void Section::debugprint(char *title)
<< " offset: 0x" << std::setw(8) << std::setfill('0') << std::hex << adjust << std::dec << std::endl;
}
-void Section::print(char *title)
+void Section::print(const char *title)
{
std::cout << std::setw(10) << std::setfill(' ') << title \
<< " name: " << std::setw(8) << std::setfill(' ') << Name \
@@ -90,7 +90,7 @@ SectionList::~SectionList()
delete sections[i];
}
-Section *SectionList::find(char *name)
+Section *SectionList::find(const char *name)
{
for (int i = 0; i < count; i++)
{
@@ -258,7 +258,7 @@ void Imports::dump(char *title)
//----- class Imports --------------------------------------------------
-Relocations::Relocations(SectionList §ionList, char *sectionName)
+Relocations::Relocations(SectionList §ionList, const char *sectionName)
{
sections = §ionList;
Section *asection = sections->find(sectionName);
Index: imagehelper/sections.h
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/sections.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 sections.h
--- imagehelper/sections.h 20 Jun 2011 14:22:01 -0000 1.1.1.1
+++ imagehelper/sections.h 20 Jun 2011 15:21:16 -0000
@@ -83,8 +83,8 @@ class Section : public SectionBase
{
public:
Section(void *FileBase, SectionHeader *p);
- void debugprint(char *title = "");
- void print(char *title = "");
+ void debugprint(const char *title = "");
+ void print(const char *title = "");
bool isIn(Section &in);
bool isIn(uint addr);
char *getName(void)
@@ -125,7 +125,7 @@ class SectionList : public Base
~SectionList();
bool add
(Section *asection);
- Section *find(char *name);
+ Section *find(const char *name);
Section *find(uint address);
// reset iterator
@@ -186,7 +186,7 @@ class Relocations : SectionBase
{
public:
// create a relocation object using section named "section" from the section list "sections"
- Relocations(SectionList §ionList, char *sectionName);
+ Relocations(SectionList §ionList, const char *sectionName);
// check for bad relocations
bool check(void);
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat