element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Support (English) ULP filesize function caches values
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Autodesk EAGLE to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 4 replies
  • Answers 1 answer
  • Subscribers 181 subscribers
  • Views 780 views
  • Users 0 members are here
Related

ULP filesize function caches values

Former Member
Former Member over 10 years ago

Can anyone make filesize return the size of the file given as its parameter? There seems to be a bug that returns the size of the previous call if the file doesn't exist. Here is some sample code that demonstrates this on my machine (7.5.0).

 

// Simple ULP to show flaw in filesize function

 

void displayFileSize(string fileName)

{

  string fSize = "";  // Initialize to empty string (size == 1?)

  fSize[0] = '\0';    // Strings are zero terminated; erase this way too!

  sprintf(fSize, "%d", filesize(fileName));

  dlgMessageBox("displayFileSize: " + fileName + "\tSize: " + fSize + ".");

}

 

void main(void)

{

  // Verify that filesize can return '0' when file doesn't exist

  // Result: displayFileSize: file.txt Size: 0.

  displayFileSize("file.txt");

 

  // Write a string to a file so it exists and has non-zero size

  output("file.txt", "wt")

  {

    printf("Here is some text to write.");

  }

 

  // Verify that this new file has a valid size

  // Result: displayFileSize: file.txt Size: 27.

  displayFileSize("file.txt");

 

  // Demonstrate that a file that doesn't exist 'has the same size' as the last

  // file that filesize() processed.

  // Result: displayFileSize: f_a_k_e__F_i_l_e.txt Size: 27.

  displayFileSize("f_a_k_e__F_i_l_e.txt");

}

  • Sign in to reply
  • Cancel
Parents
  • clem57
    0 clem57 over 10 years ago

    A work around output a null file.

     

    // Write a null string to a file so it exists and has zero size

    output("null.txt", "wt")

      {

        printf("");

      }

    displayFileSize("null.txt");

     

    Then you should get the correct results.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    Thanks. That works inserted into my trivial example, but for my real code I need to call it a bunch, so I tried throwing the workaround into a function. The results are very interesting! During debugging I created two workaround functions identical other than their names. If I call the one defined first, it works. If I call the one defined second, the workaround doesn't work. Code:

    // Simple ULP to show flaw in filesize function

     

    // Set to zero to fail, non-zero to function correctly

    int correct = 0;

     

    void displayFileSize(string fileName)

    {

      string fSize = "";  // Initialize to empty string (size == 1?)

      fSize[0] = '\0';    // Strings are zero terminated; erase this way too!

      sprintf(fSize, "%d", filesize(fileName));

      dlgMessageBox("displayFileSize: " + fileName + "\tSize: " + fSize + ".\n"

        + fileerror());

    }

     

    void displayFileSize2(string fileName)

    {

      string fSize = "";  // Initialize to empty string (size == 1?)

      fSize[0] = '\0';    // Strings are zero terminated; erase this way too!

      sprintf(fSize, "%d", filesize(fileName));

      dlgMessageBox("displayFileSize: " + fileName + "\tSize: " + fSize + ".\n"

        + fileerror());

    }

     

    // Create a zero byte file to get the size of

    void workAround(void)

    {

      fileerror();

      output("null.txt", "wtD")

      {

        printf("");

      }

      if (fileerror())

      {

        exit(1);

      }

     

      if (correct)

      {

        displayFileSize("null.txt");

      }

      else

      {

        displayFileSize2("null.txt");

        //filesize("null.txt"); // Call filesize to try & make last return value 0

      }

      dlgMessageBox("Workaround finished.");

    }

     

    void main(void)

    {

      // Verify that filesize can return '0' when file doesn't exist

      // Result: displayFileSize: file.txt Size: 0.

      displayFileSize("file.txt");

     

      // Write a string to a file so it exists and has non-zero size

      fileerror();

      output("file.txt", "wtD")

      {

        printf("Here is some text to write.");

      }

     

      // Verify that this new file has a valid size

      // Result: displayFileSize: file.txt Size: 27.

      displayFileSize("file.txt");

     

      // Try and clear 'cache'

      workAround();

     

      // Demonstrate that a file that doesn't exist 'has the same size' as the last

      // file that filesize() processed.

      // Result: displayFileSize: f_a_k_e__F_i_l_e.txt Size: 27.

      displayFileSize("f_a_k_e__F_i_l_e.txt");

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago in reply to Former Member

    Scratching head!imageimage

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • clem57
    0 clem57 over 10 years ago in reply to Former Member

    Scratching head!imageimage

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • autodeskguest
    0 autodeskguest over 10 years ago in reply to clem57

    On 2/4/2016 12:32 PM, Clem Martins wrote:

    Scratching head!:-/;\

     

    --

    To view any images and attachments in this post, visit:

    https://www.element14.com/community/message/173564

     

     

    Hi All,

     

    I've spoken to the developers, this is a confirmed bug. They are looking

    into a solution as we speak.

     

    hth,

    Jorge Garcia

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube